New111
11/20/2019, 5:32 PM!!
at the end ^^^ ?Shawn
11/20/2019, 5:33 PMNew111
11/20/2019, 5:40 PM!!
in return _fulfillmentDetails!!
... What would he gain ? And how would it change if he didn't use !!
?Shawn
11/20/2019, 5:42 PM_fulfillmentDetails
is a a private, nullable type, and the getter that they pasted in exposes a public, non-null typeShawn
11/20/2019, 5:42 PMShawn
11/20/2019, 5:44 PM_fulfillmentDetails
is a nullable var
and smart-casting cannot safely determine that it contains a non-null value in this instance, you have to tell the compiler to assert that the value is not null, or throw an NPEShawn
11/20/2019, 5:47 PMclass Example {
private var _fulfillmentDetails: FulfillmentDetails? = null
public val fulfillmentDetails: FulfillmentDetails
get() {
if (_fulfillmentDetails == null) {
_fulfillmentDetails = FulfillmentDetails(this) // initialize on first usage
}
return _fulfillmentDetails!! // need to assert/convert to non-nullable type since the declared type is non-nullable
}
}
Shawn
11/20/2019, 5:49 PM!!
this would be a compile errorShawn
11/20/2019, 5:49 PMNew111
11/20/2019, 5:50 PMdf
11/20/2019, 5:52 PM