How to check type of variable in Java?

前端 未结 14 1640
别跟我提以往
别跟我提以往 2020-11-28 05:14

How can I check to make sure my variable is an int, array, double, etc...?

Edit: For example, how can I check that a variable is an array? Is there some function to

14条回答
  •  佛祖请我去吃肉
    2020-11-28 06:08

    The first part of your question is meaningless. There is no circumstance in which you don't know the type of a primitive variable at compile time.

    Re the second part, the only circumstance that you don't already know whether a variable is an array is if it is an Object. In which case object.getClass().isArray() will tell you.

提交回复
热议问题