How to check type of variable in Java?

前端 未结 14 1618
别跟我提以往
别跟我提以往 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 05:56

    public class Demo1 {

    Object printType(Object o)
    {
        return o;
    }
     public static void main(String[] args) {
    
        Demo1 d=new Demo1();
        Object o1=d.printType('C');
        System.out.println(o1.getClass().getSimpleName());
    
    }
    

    }

提交回复
热议问题