Print the type of a Java variable

后端 未结 6 686
囚心锁ツ
囚心锁ツ 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:40

    You can use the ".getClass()" method.

    System.out.println(variable.getClass());
    

提交回复
热议问题