Relates :
|
|
Relates :
|
This code should not compile: class Main { public boolean func(Object obj) { return obj == 0; } } But javac (since JDK 7 accepts it). The following variant: class Main { public boolean func(Object obj) { return 0 == obj; } } should also not compile - but note that this was accepted since JDK 5. Relevant JLS section is 15.21. Javac seems to treat this as a reference comparison, but a reference comparison is only allowed when BOTH operands are reference types.
|