B
brian.vanheesch
I have a variable defined (local, global, parameter, field; it does
matter) such as:
MyClass abc=null;
MyClass def=new MyClass();
The variables above will house an object of type MyClass or any
subclass. Now in code, I would like to determine the specific type of
the variable. So I can do:
System.out.println(def.getClass().getName());
but what can I do for variable 'abc' ? Using the same syntax for
variable abc, will naturally result in an NullPointerException.
Is there a typeof syntax similar to instanceof?
matter) such as:
MyClass abc=null;
MyClass def=new MyClass();
The variables above will house an object of type MyClass or any
subclass. Now in code, I would like to determine the specific type of
the variable. So I can do:
System.out.println(def.getClass().getName());
but what can I do for variable 'abc' ? Using the same syntax for
variable abc, will naturally result in an NullPointerException.
Is there a typeof syntax similar to instanceof?