Print the type of a Java variable

后端 未结 6 687
囚心锁ツ
囚心锁ツ 2020-12-24 03:24

In Java, is it possible to print the type of a variable?

public static void printVariableType(Object theVariable){
    //print the type of the variable that          


        
6条回答
  •  不知归路
    2020-12-24 03:49

    You can read in the class, and then get it's name.

    Class objClass = obj.getClass();  
    System.out.println("Type: " + objClass.getName());  
    

提交回复
热议问题