Generics and Operators


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 with

Using &lt;T: Number&gt; is not an option, because Number in Kotlin does not implement plus(). &lt;T: Int&gt; says, that Int is final (and I don’t need a generic for this method).

What to do about the unrevolved reference error?



Kotlin plugin: 0.13.870 Kotlin compiler: 0.1-SNAPSHOT ( says 0.13.870)


This seems to work. However, as already said, the compiler outputs the warning "kotlin.Int is a final type...".

fun plusOp<T: Int>(var1: Var<T>,                    var2: Var<T>): Var<Int> {   return Var(var1.value + var2.value) }


It's a bug, I created issue


I looked over my source code once again.

fun plusOp<Int>(...) {}

This will create a new generic variable called Int, and has nothing to do with kotlin.Int. This code part remained from my attempts to use `<T: Number>` in the generic.

However the flickering and screen filling toolkit is irritating.


Oh, yes, if remove it all is right)