Hacker News new | ask | show | jobs
by rifung 3325 days ago
> Hey, at least they've got nullable types? That's a big win over Java right there.

Can you elaborate what you mean by nullable types?

You can set Object variables to null and with primitives you can do the same with their boxed alternatives (Integer) but I assume you mean something different?

Like the lack of types which can't be null? I can see how that's useful

2 comments

non-nullable*, Swift calls them optional types I believe. They use the same syntax for it, if you want your type to include "bottom" you add a ?

In Kotlin/Swift by default all types do not include "bottom" or "null". You add a ? to the type to indicate you may use that value, then the compiler will validate you're checking for the existence of null before you use the type.

It's one approach... I prefer the Haskell approach with a simple Maybe/Option type.

I think they meant to say that Kotlin has non-nullable types.

The Kotlin page does a good job of explaining it if you aren't familiar. It's the single most important feature that makes Kotlin worth using over Java in my opinion: https://kotlinlang.org/docs/reference/null-safety.html