TwoClocks
09/02/2020, 10:29 PMrequire(foo != null)
then after that the compiles knows foo can't be null. But if I assertTrue( foo != null)
I have to use foo?.
or foo!!.
there after. why is that? Both require
and assertTrue
throw exceptions... why can't the compiler figure it for one and not the other? Or is it just a hard-coded list of functions someplace?Russ Tennant
09/02/2020, 10:33 PMTwoClocks
09/02/2020, 10:36 PMTwoClocks
09/02/2020, 10:36 PMRuss Tennant
09/02/2020, 10:36 PMnanodeath
09/02/2020, 10:38 PMrequireNotNull
(or checkNotNull
)TwoClocks
09/02/2020, 11:36 PMephemient
09/03/2020, 12:02 AMTwoClocks
09/03/2020, 12:06 AMnanodeath
09/03/2020, 12:08 AMrequire(foo != null)
, all the contract can really say is that require(true/false) should throw or not throw. but if you say requireNotNull(foo), it can actually attach metadata to the foo more directly, such as it not being nullephemient
09/03/2020, 6:31 AMcheckNotNull()
and requireNotNull()
also return the non-null item, so it can be used in chains. similar to !!
but with better messaging