Ben Madore
01/08/2020, 6:52 PMclass Person(val email: String?)
inline class Email(val value: String)
fun Person.email() {
return this.email?.let {
Email(email)
}
}
basically an extension method on a class that will null-check a value and return it wrapped in an inline class.
how do i tell the compiler that if the function Person.email()
returns non-null then the instance.email
property is also not null.
is that possible? am i fundamentally misunderstanding contracts?LeoColman
01/08/2020, 6:53 PMLeoColman
01/08/2020, 6:53 PMRuckus
01/08/2020, 7:29 PMBen Madore
01/08/2020, 7:40 PMinstance.email()
then at some point later for some reason i need to access the raw value as instance.email
and that returns a String? when i know due to checking instance.email()
that it’s not nullBen Madore
01/08/2020, 7:42 PMinstance
is not null, it implies that property y
of instance
is also not nullKroppeb
01/08/2020, 9:37 PMDico
01/09/2020, 1:45 AMDico
01/09/2020, 1:47 AMDico
01/09/2020, 1:47 AMBen Madore
01/09/2020, 2:17 PMDico
01/09/2020, 10:21 PMBen Madore
01/14/2020, 4:36 PM