I've recently enabled the new inference algorithm with the Kotlin 1.4 nightly (1.4.0-dev-6071) compiler. I have an inline function that calls some Java code with signature:
public <T> T deserialize(..., final Type type)
like this:
inline fun <reified T: Set<Any?>> deser(...): T? = deserialize(..., object : TypeToken<T>() {}.type)
and this used to work fine with 1.4-M1 / old inference. However, now I get a runtime error when the java code attempts to return its value to the Kotlin code:
Caused by: java.lang.ClassCastException: class java.util.LinkedHashSet cannot be cast to class java.lang.Void (java.util.LinkedHashSet and java.lang.Void are in module java.base of loader 'bootstrap')
I can "solve" this by explicitly adding the
T
type to the deserialize call i.e.
deserialize<T>(...)
, but I'm wondering if this is a bug with the new type inference? The compiler does not report any errors if the
<T>
is left off.