Details
-
Bug
-
Resolution: Fixed
-
P3
-
7u40, 8
-
b98
-
Verified
Description
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.
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.
Attachments
Issue Links
- relates to
-
JDK-6979683 inconsistent interaction of reference cast with box/unbox conversions leaves out a useful case
- Closed
-
JDK-8046017 javac 1.8.0_05 unable to compile valid code (regression)
- Resolved