|
|
|
|
|
by hota_mazi
3387 days ago
|
|
> In Scala you're forced to check Options But you're never forced to use them. That's the main problem with Scala's approach: it's entirely er... optional. The Scala compiler will never tell you "You can't write a.foo() because a may be null". > Only from a Java library and that's exactly the same problem in Kotlin No, it's not. The Kotlin compiler will not let such values enter Kotlin code until you've told it precisely whether that type is nullable or not. Scala has no such mechanism so null values can enter Scala code without the compiler having any say over it. |
|
Use wartremover, then you are. Or just never write "null" (or check for it in code review). Yes ideally it just wouldn't be there, but it's really not hard to avoid it.
> The Scala compiler will never tell you "You can't write a.foo() because a may be null".
But you'll never get yourself into a position where a may be null (unless a came from a Java library, but that exact same problem can happen in exactly the same way in Kotlin). If you need to represent absence you'll use Option, and the compiler won't let you write a.foo() if a is an Option.
> No, it's not. The Kotlin compiler will not let such values enter Kotlin code until you've told it precisely whether that type is nullable or not.
No it doesn't. It lets you silently treat a type returned from a Java library as non-nullable.