Do you consider using `java.util.Optional` in kotl...
# announcements
m
Do you consider using
java.util.Optional
in kotlin to be idiomatic (given the built-in nullable types feature)?
c
when writing something new, I'm using nullability, when interfacing with something existing or writing code which can be used by java client I'm using Optional.
a
@mc it depends on how you use kotlin. if you go the functional way with Kategory its fine, if you go the usual OOP way use nullabilty
n
We have a functional codebase and use T?, not Optional
d
Unless working with a library that expects an
Optional
, or doesn’t allow nulls, I’d say Kotlin’s nullable types are favorable.
A few months back, I wrote up a migration guide for going from Java Optional to Kotlin nullable types. Here’s the link, in case it’s helpful for you - https://typealias.com/guides/java-optionals-and-kotlin-nulls/
👍 2
c
The only idiomatic way to deal with
Optional
in Kotlin is to turn these values into instances of nullable types as soon as they enter your Kotlin code, in my opinion.
r
I mostly use nullable for this. Because optional most likely a 'Optional' that might be a null reference.