Why don't we have two nulls?

后端 未结 27 1134
孤独总比滥情好
孤独总比滥情好 2021-02-02 08:38

I\'ve often wondered why languages with a null representing \"no value\" don\'t differentiate between the passive \"I don\'t know what the value is\"

27条回答
  •  醉酒成梦
    2021-02-02 08:57

    AppleInformation appleInfo;    
    while (appleInfo is null)
    {
        askForAppleInfo();
    }
    
    Apple apple = appleInfo.apple;
    if (apple is null)
    {
        sulk();
    }
    else
    {
        eatApple(apple);
    }
    

    First you check if you have the apple info, later you check if there is an apple or not. You don't need different native language support for that, just use the right classes.

提交回复
热议问题