• Java获取变量的数据类型


    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 Object part1
    StringBuffer StringBuilder append
    Java equal
    java Classloader
    Java NIO
    Oracle中Blob和Clob
    Java8 Lambda 表达式
    HashMap分析 + 哈希表
    android自定义控件之滚动广告条
    android自定义控件之模仿优酷菜单
  • 原文地址:https://www.cnblogs.com/fps2tao/p/12742274.html
Copyright © 2020-2023  润新知