Java interop: overriding methods mixing boxed and unboxed types

Hello,
I am overriding in Kotlin a Java class with the following methods:

  public JsonWriter value(boolean value) throws IOException {
    // ...
  }

  public JsonWriter value(Boolean value) throws IOException {
    // ...

My class will be used from both Kotlin and Java code (unfortunately).

Is there any way to override both methods in Kotlin?

Which one gets overridden if I do:

override fun value(value: Boolean): JsonWriter {

Thanks!

1 Like

override fun value(value: Boolean): JsonWriter { this overrides the primitive boolean. To override the boxed Boolean, use a nullable boolean: override fun value(value: Boolean?): JsonWriter {

3 Likes