如何重载 null 运算符?
我想重载一个运算符,例如 invoke
for null
文字。
例如,我可以写类似这样的内容:
null(1, 2)
可能吗?
I would like to overload an operator like invoke
for null
literal.
For example, so I could writen something like
null(1, 2)
Is it possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不建议在
null
文字上重载任何内容,因为它会导致太多混乱并且没有实际用例。不过,从技术上讲,这是可能的:
它利用了
null
关键字具有可为空类型Nothing?
的事实。I wouldn't advise overloading anything on the
null
literal, as it would cause too much confusion and would have no real-world use case.However, technically, it's possible:
It makes use of the fact that the
null
keyword has the nullable typeNothing?
.