equality



Date view Thread view Subject view Author view Attachment view

From: Tim Klinger (tklinger@us.ibm.com)
Date: Fri 21 Nov 2003 - 15:31:19 GMT


Hello all,

I am a bit confused/concerned about the semantics of equality in OCL2. The 
spec (1/6/2003) says (p. 6-3) that an expression like "x = y" evaluates to 
true if x is the same object as y.  For one thing, this is dependent on 
the mapping of symbols to objects which is not specified anywhere I've 
seen.  For example, if I implement the evaluation by creating a new object 
for each integer literal I encounter then "1 = 1" will be false according 
to this definition.  Regardless, it doesn't seem natural for the primitive 
types -- something like "1 = 1.0" will evaluate to false.  The java 
semantics for primitive types seems more intuitive.  Also, for 
non-primitive objects, object identity is often not a very useful measure 
of equality.  Maybe it would be better would be to require the evaluation 
to use an "equals" method on the types if it one were available and 
default to object identity if not.  I noticed a proposal in the 
finalization process to add equality for collection types; object identity 
will not be very useful in that case either.

Comments would be welcome.

Thanks,
Tim Klinger

Date view Thread view Subject view Author view Attachment view