Olivier Patry
03/09/2021, 2:23 PMpublic void setFoo(@NonNull Bar bar)
{
// ...
}
In Kotlin side
myObject.foo = null // OK
myObject.setFoo(null) // KO
The property access compiles 😱
The function call doesn't compile 👍
Is it expected?
Can I avoid exposing setFoo
as a Kotlin property at will?
It seems fragile to allow such property access, no?rnett
03/09/2021, 9:03 PMOlivier Patry
03/09/2021, 10:41 PM@NonNul
but @Nullable
, so I guess it brings such conflict…
My use case might be a bit weird, I have get/set and clear for this API.
In fact, what I'd like here is to disabled property feature of Java/Kotlin interop for this specific APIs.
Maybe my use case can't be achieved?Olivier Patry
03/09/2021, 10:45 PMgetFoo
isn't annotated at all 😱Olivier Patry
03/09/2021, 10:48 PMpublic class Foo {
// @Nullable
public String getFoo() { return ""; }
public void setFoo(@NonNull String bar) { }
public void clearFoo() { }
}
Olivier Patry
03/09/2021, 10:48 PM@Nullable
then
fun x() {
val foo = Foo()
foo.setFoo(null)
foo.foo = ""
foo.foo = null
foo.clearFoo()
}
Olivier Patry
03/09/2021, 10:50 PMfoo.foo
assignments will compile, if it's @Nullable
, then both assignments won't compile
Val cannot be reassigned
Olivier Patry
03/09/2021, 10:50 PMsetFoo