class Test
{
public static void main(String[] args)
{
int i=1;
System.out.println(getType(i));
}
public static String getType(Object o){
return o.getClass().toString();
}
}
public class Test15 { public static void main(String[] args) { int i=1; Integer i1 = 2; double d = 1.8; long l = 76; boolean b = false; System.out.println(getType(i)); System.out.println(getType(i1)); System.out.println(getType(d)); System.out.println(getType(l)); System.out.println(getType(b)); } public static String getType(Object o){ return o.getClass().toString(); } public static String getType(int o){ return "int"; } public static String getType(byte o){ return "byte"; } public static String getType(char o){ return "char"; } public static String getType(double o){ return "double"; } public static String getType(float o){ return "float"; } public static String getType(long o){ return "long"; } public static String getType(boolean o){ return "boolean"; } public static String getType(short o){ return "short"; } }
obj.getClass().getName() ===〉 java.lang.Integer
obj.getClass().toString() ===〉 class java.lang.Integer
public static void getType(Object object) {
int length = object.getClass().getName().lastIndexOf(".");
String type = object.getClass().getName().substring(length + 1);
System.out.println(type);
}
基本类型不能得到