[Bluej-discuss] confusion over = (and == ?)

Carl Alphonce alphonce at cse.Buffalo.EDU
Fri Nov 30 22:16:43 GMT 2007


Ian Barland <ibarland at radford.edu> wrote:
> I'd argue that == is overloaded, and even mention in CS1:
>   == : int, int --> boolean
>   == : double, double --> boolean
>   == : Object, Object --> boolean    (once we have talked about references)

Hi Ian,

You're right, I should have been more careful in my language.  The 
context of my comment was the following:

  > [...] in Java the "==" is overloaded to mean 'the same value' for
  > primitives and 'the same instance' for objects.

exp1 == exp2 compares the values of the two expressions exp1 and exp2. 
Yes, the types of exp1 and exp2 have to be compatible, but checking for 
equality of two references (memory addresses) is essentially the same as 
checking for equality of two int values or two double values.  There was 
an artificial (in my mind) distinction being drawn between how "==" 
operates on primitives and how "==" operates on references.

Best,
Carl

------------------------------------------------------------------------
            ()  ascii ribbon campaign - against html e-mail
            /\
------------------------------------------------------------------------
Carl Alphonce                                   alphonce at cse.buffalo.edu
Dept of Computer Science and Engineering       (716) 645-3180 x115 (tel)
University at Buffalo                          (716) 645-3464      (fax)
Buffalo, NY 14260-2000              www.cse.buffalo.edu/faculty/alphonce


More information about the bluej-discuss mailing list