https://kotlinlang.org logo
#getting-started
Title
# getting-started
m

Matias Reparaz

07/08/2021, 8:39 PM
Hi, I’m upgrading from 1.3.50 to 1.5.20 and I have this problem. This code now compiles
Copy code
class SomeClass<out T>(private val type: Class<T>, val getDefaultValue: () -> T) {
    constructor(type: Class<T>, default: T): this(type, {default})
}
but when I upgrade I have this error
Copy code
Kotlin: Overload resolution ambiguity: 
public constructor SomeClass<out T>(type: Class<TypeVariable(T)>, getDefaultValue: () -> TypeVariable(T)) defined in SomeClass
public constructor SomeClass<out T>(type: Class<TypeVariable(T)>, default: TypeVariable(T)) defined in SomeClass
can someone explain me why this doesn’t work anymore and/or how can I rewrite it?
e

ephemient

07/08/2021, 8:48 PM
intentional change to fix other errors in type inference
Copy code
class SomeClass<out T>(private val type: Class<T>, val getDefaultValue: () -> T) {
    constructor(type: Class<T>, default: T): this(type, getDefaultValue = { default })
}
will compile
m

Matias Reparaz

07/08/2021, 8:51 PM
perfect! 🙏