Is it possible to get the type of a variable declared (but not instantiated) in Java? eg:
public class Foo {
FooTwo foo2;
FooTwo foo3;
FooThree foo4;
public static void main(String[] args) {
if (foo2.getClass() == foo3.getClass()) {
System.out.println("foo2 is the same type as foo3");
}
if (foo3.getClass() == foo4.getClass()) {
System.out.println("foo3 is the same class as foo4");
}
}
}
With an exit:
foo2 is the same type as foo3
obviously, the method getClass()does not work with an immutable variable, so this code does not work. I assume that the information I'm looking for is stored somewhere in a variable (pointer?) For type safety and that it may be available. Can this comparison be achieved?
:
. , , ArrayList . , ( ) , arraylist , , ( ).
: . .