public class Ambiguity {
public static void main(String[] args) {
int Integer = 3;
System.out.println((Integer) null); // cast; prints "null"
System.out.println((Integer) - Integer); // subtraction; prints "0"
System.out.println((Integer) (-Integer)); // cast; prints "-3"
}
}
In Java, I can declare a variable named Integer, and then write code that could be a cast to the Integer class or an expression involving the Integer variable. How does Java resolve the ambiguity between class names and variable names? Is there a formal rule somewhere in the spec? Is it an ad-hoc heuristic thing? I know C compilers have to deal with a similar problem, and I know how they deal with it, but Java seems to be more permissive.
Integer/integer. - Bernhard Barker