https://kotlinlang.org logo
d

dsgryazin

01/10/2017, 12:40 PM
@kirillrakhman Developer can make additional assumptions about nullability before using java code. Yep, passing arguments to java methods was a bad example - however, i think it could be useful to know, that java code possibly doesn't expect nullable, though it's not marked as
@NonNull
- nullability contracts in java are broken too often. When I use Kotlin and it says that arguments are ok - I'm sure nullability is ok. Can't say that about java. Often you even don't understand that you call java and that's why I want special inspection. I see two critical examples: 1. You override Java method. Today Kotlin plugin automatically makes
?
-arguments unless
@NonNull
specified, but accidental
T!
happens causing NPE. 2. Java method returns value. Kotlin automatically infers
T!
and allows using it as
nonnull
leading to NPE. See, platform types too easy to use as
nonnull
accidentally, by fault. And there is no help from lint, except
"Function or property has platform type"
that doesn't cover all platform types usages.