java determines whether it is a Long type
1. First define a getType method to receive a parameter of type Object;
2. Then use the getClass method to obtain the class type object;
3. Then use the toString() method to convert it to a string, and use substring to intercept the string. Get the variable type;
4. Finally, compare the variable type with the Long string
public class HelloWorld { public static void main(String[] args) { Boolean res = getType(1232343234L); if(res) { System.out.println("是Long类型"); }else{ System.out.println("不是Long类型"); } } public static Boolean getType(Object o) { String type = o.getClass().toString(); System.out.println(type); type = type.substring(type.lastIndexOf('.') + 1, type.length()); if("Long".equals(type)) { return true; } return false; } }
(Related video tutorial sharing: java video tutorial)
The above is the detailed content of Java determines whether it is a Long type. For more information, please follow other related articles on the PHP Chinese website!