How do you know a variable type in java?

后端 未结 7 1757
野性不改
野性不改 2020-11-30 18:07

Let\'s say I declare a variable:

String a = \"test\";

And I want to know what type it is, i.e., the output should be java.lang.String

7条回答
  •  伪装坚强ぢ
    2020-11-30 19:03

    Use operator overloading feature of java

    class Test {
    
        void printType(String x) {
            System.out.print("String");
        }
    
        void printType(int x) {     
            System.out.print("Int");
        }
    
        // same goes on with boolean,double,float,object ...
    
    }
    

提交回复
热议问题