annotations - Annotate Type Parameter in Java for Kotlin Compiler -
in java, have following method:
public optional<foo> getfoo() { // return non-null value } in kotlin code, return type of method given optional<foo!>!. using @nonnull annotation can cut down optional<foo!> (i.e. foo type not null-checked anymore).
is there way annotate method make kotlin compiler null-check return value correctly?
you can annotating type use of foo of nullability annotations kotlin compiler understands. unfortunately, annotation libraries list don't support type use annotation.
i found @notnull org.jetbrains:annotations:15.0 (but not 13.0) has type_use target, can add library dependency project , annotate type use:
import org.jetbrains.annotations.notnull; ... public @notnull optional<@notnull foo> getfoo() { // return non-null value } then return type seen optional<foo> in kotlin.
this, of course, can done other nullability annotations list mentioned above support type_use target.
Comments
Post a Comment