3 ms·
> I don't quite get the problem as stated in the article. > Here foo is defined as nullable, hence the problem. How do you know it's "the problem"? The answer
by masklinn 9y ago
> I don't quite get the problem as stated in the article.
> Here foo is defined as nullable, hence the problem.
How do you know it's "the problem"? The answer is that you don't until it blows up in your face, because this is a Java interop call.
And of course the local could come from an other call into Java which returns a nullable reference, or it could make complete sense for it to be nullable.
- smichel17 9y agoRemove part of your sentence, and I think you've answered your own question. > How do you know it's "the problem"? [...] because this is a Java interop call. If you're making platform calls, you know you have to deal with nulls (or at least, you should, in my opinion). So you declare returns nullable and avoid passing nulls unless that's documented to be okay. Kotlin's Elvis operator makes this really easy: val a: String? = null val b: String = a ?: "alternative"