Java获取变量的数据类型
2021-02-10 13:20
标签:block http print 类型 bsp article double lan OLE 运行结果: 转 : https://blog.csdn.net/qq_36728361/article/details/89217682 Java获取变量的数据类型 标签:block http print 类型 bsp article double lan OLE 原文地址:https://www.cnblogs.com/fps2tao/p/12742274.htmlpublic class Int_String_Char {
public static void main(String[] args) {
byte a1=2;
short a2=2;
int a3=1;
long a4=2L;
System.out.println(getType(a1));
System.out.println(getType(a2));
System.out.println(getType(a3));
System.out.println(getType(a4));
float f=1.00f;
double d=1.00d;
System.out.println(getType(f));
System.out.println(getType(d));
boolean b=true;
System.out.println(getType(b));
char c=‘a‘;
System.out.println(getType(c));
String s="abc";
System.out.println(getType(s));
}
private static String getType(Object a) {
return a.getClass().toString();
}
}
class java.lang.Byte
class java.lang.Short
class java.lang.Integer
class java.lang.Long
class java.lang.Float
class java.lang.Double
class java.lang.Boolean
class java.lang.Character
class java.lang.String