First of all:
Does instanceof
produce a static type qualifier?
Not at all. It is just an operator that returns a boolean result. It tells you if A is an instance of B
. Not more, not less.
In Java, all type information (at least at runtime) boils down to the things that java.lang.Class gives you.
In other words: when you int foo = 3
in Java, the best thing you hope for would be Class<?> bar = int.class
. Also note that there is no generic way to get to the Class object of "something".
The only slightly "advanced experience" was added with the new var
keyword. Which basically allows you to now write down types explicitly, but let the compiler handle them completely.
The one additional semantical element that var
gives you: the ability to "name" something that otherwise has no name:
var obj = new Object() {
private void test() {
System.out.println("anonymous test");
}
};
obj.test(); // works!
( from the java specialist newsletter, issue 263 )
cast
instead in java – Eugene May 27 at 10:41