Segfault (NullPointerException) in Linux

Jarrett Billingsley jarrett.billingsley at gmail.com
Wed Mar 18 16:19:30 PDT 2009


On Wed, Mar 18, 2009 at 6:44 PM, Qian Xu <quian.xu at stud.tu-ilmenau.de> wrote:
> Frank Benoit wrote:
>>
>> Qian Xu schrieb:
>> ----------- code 2 (current solution) --------------
>>>
>>> public test(MyObj obj)
>>> {
>>>  if (obj !is null &&
>>>      obj.getObj2 !is null &&
>>>      obj.getObj2.getObj3 !is null)
>>>  {
>>>     obj.getObj2.getObj3.test();
>>>  }
>>> }
>>>
>>> ------------------------------------------------------
>>
>> If you want to be able to return something like "nothing", you can use
>> NullObject. That is, return an object that lets you navigate the
>> references and lets you test for it being a "null" object.
>>
>> auto o = obj.getObj2.getObj3;
>> if( !o.isNull() ){
>>    o.test();
>> }
>
> Hi, I have tried your code
>
> But gdc said, "Error: no property 'isNull' for type
> 'NullPointerExceptionTest.MyObj'
>
> Did I miss something?

He's talking about this, I think:

http://en.wikipedia.org/wiki/Null_Object_pattern


More information about the Digitalmars-d-learn mailing list