Corda - Purpose of NULL_PARTY

一曲冷凌霜 提交于 2019-12-25 01:06:58

问题


What is the purpose of NullKeys.NULL_PARTY?

For example, when should I use

party: AbstractParty = NullKeys.NULL_PATRY

Rather than

party: AbstractParty? = null

回答1:


party: AbstractParty? = null

The above defines a nullable variable i.e. party will either be an AbstractParty or it will be null

party: AbstractParty = NullKeys.NULL_PARTY

The above on the other hand, will never result in party being null, but rather you'll end up with an AnonymousParty with a null public key.

NULL_PARTY could come in useful during unit testing, particularly when testing for equality, but it's not advised to use it for production code.




回答2:


!= NULL_PARTY works just as well as != null and removes the nuisance of not-null assertion/safety operators when you can be sure the value will not be used, e.g. an owner for a state that has not been purchased by one.

See also sample uses in Corda's repo.



来源:https://stackoverflow.com/questions/54450888/corda-purpose-of-null-party

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!