Came across some Platform type issues related to a...
# announcements
r
Came across some Platform type issues related to annotations this week, and while I've used platform types before, never really thought deeply as to why they exist. Seems like everything that's returned from Java could just be treated as nullable. Looking at the docs:
Copy code
Any reference in Java may be null, which makes Kotlin's requirements of strict null-safety impractical for objects coming from Java. Types of Java declarations are treated specially in Kotlin and called platform types. Null-checks are relaxed for such types, so that safety guarantees for them are the same as in Java
It seems as though it was a conscious decision to make the platform conform to Java. There are tradeoffs with all those choices, but curious as to why the reasoning was made to create the platform type instead of treating everything as nullable?
d
Generics (and other stuff I can't remember)! It was more pragmatic to make the Kotlin compiler calm down about types from java than try and work around the nullability.
There's a video on YouTube where Abreslav talks about this.

https://www.youtube.com/watch?v=zVZFv80l_lQ

r
Very cool. I'll check it out!
i
Android Studio has unknown nullness lint warnings for this.