What's wrong with this code?
Steven Schveighoffer
schveiguy at yahoo.com
Mon Jan 10 08:05:06 PST 2011
On Sat, 08 Jan 2011 15:46:01 -0500, Michal Minich
<michal.minich at gmail.com> wrote:
> On Sat, 08 Jan 2011 20:34:39 +0000, Sean Eskapp wrote:
>
>> if(left == null)
>
> 1) write if (left is null) instead if checking for null. Equality
> operator is rewritten to a.opEquals(b), which you don't want if you
> checking for null.
Actually, this is no longer true. For comparing two classes or
interfaces, a == b becomes .opEquals(a, b) which is defined in object.di
and properly handles null references.
However, if checking for null, a is null is going to be more correct and
as efficient as possible (a == b should be inlined to the same thing, but
only if you have inlining enabled).
-Steve
More information about the Digitalmars-d-learn
mailing list