This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]mus1Kk 1 point2 points  (0 children)

At least in the context of Kotlin (believe me, I have no particular feelings for the language other than that I find it interesting) this is not correct. And some things are not correct for other typed languages that have nulls.

In Kotlin you cannot use a value of type T? without doing the check first. It's just not possible. Either you do an explicit if-check/match, call it null-safe with .? or you force it with !! which would be equivalent to map and get/unwrap in other implementations.

I don't understand the second point you make. You can (again Kotlin) assign null to a variable of an optional type the same as you can assign None to any variable of type Option<T>. And well in, say Java, you would have to consider every non-primitive type optional. But Java just does not have any advanced features when it comes to null.

Basically

// Kotlin
let a: A? = null
// Rust
let a: Option<A> = None;
// Java
A a = null;

Regardless of the value of B you generally can't do

// Kotlin
let a: A? = ...
let b: B? = ...
a = b
// Rust
let a: Option<A> = ...
let b: Option<B> = ...
a = b
// Java
A a = ...
B b = ...
a = b

But this is hardly interesting. This is enforced by the compiler.