If you try to call a method with Kotlin's default arguments from Java, you will get an error.
Annotate @JvmOverloads
Kotlin side
class Foo {
@JvmOverloads fun bar(str: String = "A"): String {
return str
}
}
Java side
Foo foo = new Foo();
foo.bar(); // "A"
foo.bar("B"); // "B"
@JvmOverloads
Error when not annotatingjava.lang.IllegalArgumentException: Parameter specified as non-null contains null
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.jvm/-jvm-overloads/index.html
Recommended Posts