At the risk of Tim Holloway going on about people who avidly read the Java® Language Specification (=JLS), the compiler “knows” that the == test cannot evaluate to true because the two variables are of different types. Hence the compile time error. The compiler only “follows” the value of a variable when that variable counts as a constant variable.
Jesse Silverman wrote:. . . will not even compile in Java.
It is illegal to ask if the references are to the same Object, the compiler knows the answer already: "Nope!" . . .
I think you have miusnderstood BG's point, which he explains himself.
Your line is too precise . . .
Agree: there are several circumstances where it is all right to use == :-
"Don't use == to compare strings for equality. Learn when it will return true to get a good score on the OCJP and forget about it later."
Quite right. People get confused when they see...and they think that x is an object rather than a reference. Remember that with escape analysis, that x might not be created on the heap at all.
. . .the words "references to" be in there . . . everything (except the 8 primitives) is a reference, so it is perceived to be superfluous.
Jesse Silverman wrote:
In terms of the sentence in the summary on page 208, I would change it to:
'Calling == on String references will check whether they point to the same object'
Jesse (edited) wrote:
'Calling == on (compatible type) references will check whether they point to the same object'