Also I have this question which I hope you could a...
# announcements
t
Also I have this question which I hope you could answer: when should I use nullable types in Kotlin? Should you always use nullable types or just when they are needed? I am a bit confused. Thank you.
y
You should use non-optional (non-nullable) types where possible, and nullable only if absolutely needed.
👍 2
k
Please keep it to one channel only
2
n
the compiler guarantees that you will never get a null-pointer exception with non-nullable types (e.g.
String
or
Int
). Thus, as @Yev Kanivets said: if you can, use non-nullable types. However , sometimes the business logic or an external API does not allow that (e.g. an optional filter parameter to a query method).
s
Nullable types are perfectly fine to use I'm Kotlin. They are a proper type in Kotlin (unlike in Java). You usually use them when modeling an optional value.
l
Why are not y'all replying in bold?