Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It's exactly as elegant for nulls. Kotlin's T? == Scala 3's T | Null. In both Scala 3 and Kotlin, you can't call a method it.

Kotlin does have the !! operator for practical purposes like Java interop. Equivalent to this Scala 3 code:

   extension (t: T)
     def !!: T = if(t != null) t else throw NullPointerException()

I haven't checked after release, how is Scala 3 smart-casting now? E.g. Kotlin and Typescript convert a T? to a T inside an if(t != null) branch, and Scala's left much to be desired when I checked.

Scala's and Typescript's union & intersection + smartcasting approach is much more general than Kotlin's T? of course, but Kotlin could introduce that backwards-compatible if they wanted.



  > "I haven't checked after release, how is Scala 3 smart-casting now? E.g. Kotlin and Typescript convert a T? to a T inside an if(t != null) branch, and Scala's left much to be desired when I checked."
See: https://docs.scala-lang.org/scala3/reference/other-new-featu...

It works perfectly well in a number of ways (IE, you can use "=="/"!=" null, use a "match")

https://scastie.scala-lang.org/s853XsLoQEKTVosebJHelA

Kotlin is still a better experience when interacting with Java because of inbuilt interop with Java types like "List" though, in my opinion.

In Scala you need to use ".asScala", ".asJava" etc.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: