https://kotlinlang.org logo
#announcements
Title
# announcements
m

mathew murphy

07/11/2019, 5:44 PM
Is there a way to tell Kotlin to convert all instances of
java.lang.String
to
String?
rather than
String!
within a specified context, so that I get errors or warnings if I try to do (say)
resultset.getString(2).trim()
?
🚫 2
g

groostav

07/11/2019, 6:37 PM
"within a specific context", I mean the type system might do it. would using an explicit type
val resultSet: List<String?> = somejavaAPI.getResults()
solve your problem? also, if the java API your getting your
resultset
back from is one you control, then kotlin will respect JSR 305 annotations, so you can download a copy of JSR 305 and use the `Nullable`/`Nonnull` annotations, and the calling kotlin code will stop using the platform type
m

mathew murphy

07/11/2019, 8:32 PM
The API is JDBC, so I don't really control it. I guess eventually there will be a new version that has JSR 305 annotations...
a

Alexey Belkov [JB]

07/12/2019, 7:59 AM
Kotlin 1.3.40 with its support of external annotations in IDEA might do what you want: https://blog.jetbrains.com/kotlin/2019/06/kotlin-1-3-40-released/. It's not mentioned in the blog post, but Intellij IDEA can infer such annotations automatically for Java libraries, for example the JDK. This will only work in the IDE though.