[Bluej-discuss] confusion over =

Lon Levy LXL at oregon.k12.wi.us
Fri Nov 30 18:29:10 GMT 2007


Hi Kyle,

You say that "==" is not overloaded.  Perhaps overloaded is the wrong term, but the concept is there.  Java in a Nutshell, Table 2-4 lists it twice:

  ==    primitive, primitive      equal (have identical values)
  ==    reference, reference    equal (refer to the same object)

When there are two methods of the same name, one of which has two primitives as parameters and the other has two references as parameters, the methods are said to be overloaded.  Thus, my use of the term.  "==" is not a method, it is a comparison operator, so it is not quite the same thing.

I think we are all saying the same thing (including a couple of people who wrote me off-list), just using different terminology.  Students getting confused over this should not be surprising.

Regards,

Lon.

Lon Levy, MS-CSEd
Computer Science Teacher
Volunteer Computer Club Advisor
Oregon High School
608-835-1316
 
Lon.Levy at oregonsd.org
LXL at oregon.k12.wi.us
cs at levytree.net

non somnos requiem


>>> Kyle Gillette <scheme2java at yahoo.com> 11/29/2007 11:46 PM >>>
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/ 
_______________________________________________
mailing list bluej-discuss at bluej.org 
To unsubscribe or change your preferences, go to
http://lists.bluej.org/mailman/listinfo/bluej-discuss



More information about the bluej-discuss mailing list