Douglas Pearson doug-list-S/DimaiMjl4qNzItGZwj4Q@public.gmane.org [seajug]
2014-07-09 00:51:36 UTC
Is it fair to say that virtually all Java developers feel that the behavior
of == in Java is a mistake? That it should in fact call the .equals()
method on an object instead of doing instance equality?
If so - is there any process where this could actually get changed in the
language?
I'd propose:
== calls .equals() if the LHS is an object
=== (a new operator) would do instance equality - if you really really
want it
Sure, a change like this would theoretically not be backwards compatible.
You could be relying on == to not do the more general equals test. But
it's hard to imagine this is a common practice and the fix would be trivial
(move to the === operator).
Seems to me this causes more than it's share of Java bugs - switching
between "Integer" and "int" for a definition usually produces almost no
changes (thanks to boxing) except the semantics of == silently changes
Oh well... I can dream right?
Doug
of == in Java is a mistake? That it should in fact call the .equals()
method on an object instead of doing instance equality?
If so - is there any process where this could actually get changed in the
language?
I'd propose:
== calls .equals() if the LHS is an object
=== (a new operator) would do instance equality - if you really really
want it
Sure, a change like this would theoretically not be backwards compatible.
You could be relying on == to not do the more general equals test. But
it's hard to imagine this is a common practice and the fix would be trivial
(move to the === operator).
Seems to me this causes more than it's share of Java bugs - switching
between "Integer" and "int" for a definition usually produces almost no
changes (thanks to boxing) except the semantics of == silently changes
Oh well... I can dream right?
Doug