How do you know a variable type in java?

后端 未结 7 1761
野性不改
野性不改 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:01

    If you want the name, use Martin's method. If you want to know whether it's an instance of a certain class:

    boolean b = a instanceof String

提交回复
热议问题