The following code will show an unresolved reference error for the `+`-sign in the editor. It lists a long list of candidates and the tooltip flickers when I hover my cursor over the `+`-sign.
data class Var<T>(var value: T)
fun plusOp<Int>(var1: Var<Int>,
var2: Var<Int>): Var<Int> {
return Var(var1.value + var2.value)
}
I wanted to overload the plus method for Var
. Instead I created plusOp()
, because the editor somehow mixed Int.plus()
with Var.plus()
.
Using <T: Number>
is not an option, because Number in Kotlin does not implement plus()
. <T: Int>
says, that Int is final (and I don’t need a generic for this method).
What to do about the unrevolved reference error?
–Benjamin