How to check for null references

Tim Healey leikeze at gmail.com
Mon Aug 27 05:49:47 PDT 2007


Use 'is' to test for null:

if ( o is null ) { ... }

 From http://www.digitalmars.com/d/expression.html#IdentityExpression : 
For class objects, identity is defined as the object references are for 
the same object. Null class objects can be compared with is.

The run-time error you got is because the program was essentially 
executing this:

if ( o.opEquals( null ) ) { ... }

This is intended behavior, though I'm not finding the right spec page to 
link you to at the moment.



More information about the Digitalmars-d mailing list