How do you know a variable type in java?

后端 未结 7 1705
野性不改
野性不改 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 ...
    
    }
    
    0 讨论(0)
提交回复
热议问题