What is the purpose of null?

后端 未结 25 2534
别那么骄傲
别那么骄傲 2020-12-07 22:24

I am in a compilers class and we are tasked with creating our own language, from scratch. Currently our dilemma is whether to include a \'null\' type or not. What purpose do

25条回答
  •  爱一瞬间的悲伤
    2020-12-07 23:12

    Use a null object pattern!

    If you language is object oriented, let it have an UndefinedValue class of which only one singleton instance exists. Then use this instance wherever null is used. This has the advantage that your null will respond to messages such as #toString and #equals. You will never run into a null pointer exception as in Java. (Of course, this requires that your language is dynamically typed).

提交回复
热议问题