Comparing apples and oranges

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Tue Sep 29 09:10:59 PDT 2009


Ary Borenszweig wrote:
> Andrei Alexandrescu wrote:
>> Consider:
>>
>> class Apple {}
>> class Orange {}
>>
>> void main() {
>>     writeln(new Apple == new Orange);
>> }
>>
>> This program always prints "false".  By and large, it is odd that one 
>> would attempt comparison between unrelated classes. I was thinking, is 
>> this ever legitimate, or we should just disallow it statically 
>> whenever possible?
> 
> Has this brought problems to anyone ever?

I'm not sure about this particular aspect, but in Java the related 
method equals() has been a perennial source of issues. Just google for 
java equals.

Andrei



More information about the Digitalmars-d mailing list