Java获取变量的数据类型

2021-02-10 13:20

阅读:447

标签:block   http   print   类型   bsp   article   double   lan   OLE   

 

public 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

 

 

 

转 : 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.html


评论


亲,登录后才可以留言!