https://kotlinlang.org logo
#feed
Title
# feed
d

Dave Leeds

10/30/2017, 10:52 PM
How to migrate from Java 8
Optional
to Kotlin's null-safety features. https://typealias.com/guides/java-optionals-and-kotlin-nulls/
👍 2
a

artem_zin

10/30/2017, 11:02 PM
There might still be one case when you’d use an Optional in Kotlin
Second case is when API you’re working with doesn’t support null values, like RxJava 2 Plus you can add that Kotlin nullable saves an allocation in compare to Optional in exchange to != null checks added by compiler (although Optional needs to be dereferenced, so Kotlin nullable should win overall) Other than that — really good migration guide 👍
r

raulraja

10/30/2017, 11:06 PM
In case anyone is interested in a safe Option type in Kotlin there is also http://kategory.io/docs/datatypes/option/
👍 2
contains no unsafe APIs and monad comprehension among other features
a

artem_zin

10/30/2017, 11:08 PM
Or a more minimalistic one
<https://github.com/gojuno/koptional>
👏 1
d

Dave Leeds

10/31/2017, 12:57 AM
@artem_zin and @raulraja - Thanks for your comments! I haven't looked at Kategory's Option or koptional, so I'm going to go check 'em out. Do you all mind if I incorporate your feedback into the article?
a

artem_zin

10/31/2017, 1:00 AM
@Dave Leeds sure, go ahead 🙂
r

raulraja

10/31/2017, 2:12 AM
@artem_zin please and thank you for your article!
It's already is helpful to people wondering about the differences. I learnt new stuff reading it.
a

artem_zin

10/31/2017, 2:25 AM
I guess you meant djleeds 😄
o

Oleksii

10/31/2017, 2:17 PM
By the way, it is possible to define all the Optional methods on nullable as extension methods. Then change Option<Type> to Type? and fix all the compile errors with alt+enter. Then inline these extension methods. You are done with the migration. I'm not 100% sure it will work with all Optional's methods, but it worked on my previous project very well.
r

raulraja

10/31/2017, 2:26 PM
@artem_zin yeah sorry I ment to mention @Dave Leeds xD
👍 1
🙂 1
d

Dave Leeds

10/31/2017, 5:26 PM
@Oleksii That's a clever idea! I'll have to give that a try.
4 Views