Good morning, everyone. I’m having trouble with K...
# getting-started
d
Good morning, everyone. I’m having trouble with Kotlin’s type system while extending an existing Java class. Could someone take a look at the following gist and help me out?
j
Try replacing
Any
with
Any?
in the class header? Just a guess.
Just looking at the difference between the java code and kotlin code,
Object
is the same as
Any?
, not
Any
d
Do you mean the first argument to the ctor or the type of the first generic?
But I get the same result with the following implementation
Copy code
class MapEqualJsonBinaryType : MutableDynamicParameterizedType<Any?, JsonBinaryJdbcTypeDescriptor, JsonJavaTypeDescriptor> {
    constructor() : super(
        Any::class.java as Class<Any?>,
        JsonBinaryJdbcTypeDescriptor.INSTANCE,
        MapEqualJsonJavaTypeDescriptor(JsonConfiguration.INSTANCE.objectMapperWrapper)
    )

    constructor(objectMapperWrapper: ObjectMapperWrapper) : super(
        Any::class.java as Class<Any?>,
        JsonBinaryJdbcTypeDescriptor.INSTANCE,
        MapEqualJsonJavaTypeDescriptor(objectMapperWrapper)
    )
}
Anyone? 🙂
a
It is difficult to see the problem without a minimal project with relevant dependencies and participating code-files. Your error-message in the gist-comment suggests that the
forEachJdbcType
-param
action
should be declared as nullable somewhere in a derived class, I think maybe the Java-code marks it as
@Nullable
and the kotlin-compiler tries to honor that (since it explains it needs the param-type
IndexedConsumer<*>?
).
You should be able to let IntelliJ (if you are using that) suggest a quickfix by generating a fitting method-override in the kotlin class. Or you could try to make the param
@Nullable
in the default implementation.
d
Hey Arne, I just pushed a minimum failing project to github: https://github.com/rebuy-de/kotlin-type-system
w
It smells like a compiler bug to me, because the code works in Kotlin 2.1.0 when I tested it
d
Oh, interesting
Unfortunately we won't move to Kotlin 2.x before Spring Framework 7 is shipped
Justed verified that it compiles with Kotlin 2.1.0, yet IntellIJ shows an error
image.png
w
Perhaps your IntelliJ is still in K1 mode
d
not sure what else could be changed
w
Try finding the K2 setting. It's a checkbox somewhere in the settings. Should be conveniently findable via search in settings.