Wesley Hartford
06/12/2024, 4:08 PM@Nonnull
. Kotlin knows that my implementing function should have non-null types for those parameters. The only problem is, the Java code which calls the interface passes null
for these @Nonnull
annotated parameters. Kotlin, of course, throws an exception when null
is passed to a non-null type. I'd like to change the signature of my function to have nullable types, but then Kotlin tells me that its no longer implementing the function it should be. Is there any way to tell Kotlin to ignore the annotations on that method or the specific parameters? I've filed a bug report with the maintainer of the interface, but I'd like to move forward before the fix is released.Wesley Hartford
06/12/2024, 4:09 PMannotations.xml
file, but it doesn't seem to override the annotations in code.Klitos Kyriacou
06/12/2024, 4:29 PM// BadInterface.java
interface BadInterface {
void foo(@Nonnull String bar);
}
// GoodInterface.java
interface GoodInterface extends BadInterface {
@Override
void foo(@Nullable String bar); // Java compiler ok with this, ignore IDE warnings
}
// Kotlin code
class MyObj : GoodInterface {
fun foo(bar: String?) {...}
}
val myObj: BadInterface = MyObj()
myObj.foo(null)
Wesley Hartford
06/12/2024, 4:31 PMkqr
06/13/2024, 7:14 AMKlitos Kyriacou
06/13/2024, 8:33 AMWesley Hartford
06/13/2024, 2:02 PM