|
|
|
|
|
by lmm
3383 days ago
|
|
> But you're never forced to use them. 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. |
|
Well, yes, that's my point: that the Scala compiler can't do it, so you need an external tool to do it for you.
It's a similar argument to a dynamic language programmer saying their language is statically typed, you just need to use that external tool to type check it.
> 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)
Again, no it can't.
Types coming from Java are marked as "platform types" by the Kotlin compiler and they are not allowed in the Kotlin code base. You need to convert them to a bona fide Kotlin type first (basically, decide if it's a nullable type or not).
It's the third time I've mentioned this and you keep ignoring it.
In contrast, Scala happily lets Java types enter the Scala object world, along with its null values.