Null Object works still fine

Marco Leise Marco.Leise at gmx.de
Sat Aug 11 15:37:57 PDT 2012


Am Sun, 12 Aug 2012 00:23:10 +0200
schrieb "Namespace" <rswhite4 at googlemail.com>:

> This code works fine but it shouldn't, or?
> 
> http://dpaste.dzfl.pl/b9027fff

That's fine. There is no check for null at every possible occasion, like I think in Java. The operating system will catch any actual null dereference though, by notifying you of an invalid memory access.
So in other words, D uses the fast approach.

Cases where your print will not work is, when print() is a virtual method of that class (one that can be overridden). That would need to actually dereference the object to take a look into the virtual method table.
'private' and 'final' methods (or methods of a 'final class') are not virtual.

-- 
Marco



More information about the Digitalmars-d-learn mailing list