QUOTE(baavgai @ 10 May, 2008 - 02:29 AM)

Yep, you're correct. Though I've never actually managed to get Java to fail on the == for a string instance, it technically could.
Baavgai,
If you use the same constant in the same .java file there will be ==
So:
CODE
class AClass {
String x = "abc";
... 2 thousands lines of code
String y = "abc"
}
then
x == y
and x == "abc" and y == "abc"
because the compiler optimizes the use of constants.
even
CODE
AClass instance1, instance2;
instance1.x == instance2.y;
But in this case scan.next() return a String build in the object scan that point to a location in memory (built from the InputStream) wich is surely not the same as the one where points your constant "Y" in Class Hangman.
But the Java compiler is brighter than you think
CODE
String a = "xy";
String b = "x" + "y";
System.out.println(a == b);
String c = "y";
b = "x" + c;
System.out.println(a == b);
prints:
true
false
This post has been edited by pbl: 10 May, 2008 - 09:00 PM