[Bluej-discuss] confusion over =
Kyle Gillette
scheme2java at yahoo.com
Fri Nov 30 05:46:06 GMT 2007
Lon Levy wrote:
I would be careful with using "is equal" for "==". Instead, I use "is the same as". This is important because in Java the "==" is overloaded to mean 'the same value' for primitives and 'the same instance' for objects.
I don't think that == is overloaded at all. For both primitives AND references it is comparing the values stored within the variables. If two references refer to the same object, then they are equal, because their references have the same contents - perhaps an address, :-o. The real problem for students is thinking that == compares the two objects when it does not. I believe that this confusion comes from the way we can treat primitives. I try to create references for each object that is instantiated. I know that there are instructors who do not believe in teaching it this way.
Point a; // a [_] lame attempt at drawing a box
a = new Point(3,5); // a[_]--->[3,5]
Kyle
____________________________________________________________________________________
Be a better pen pal.
Text or chat with friends inside Yahoo! Mail. See how. http://overview.mail.yahoo.com/
More information about the bluej-discuss
mailing list