Kotlin generics

Hello every body.
I want to do some thing like this

data class TestGen<T: Number>(var x : T, var y : T)

public operator<T:Number> fun Int.plus(p:TestGen<T>) = TestGen(this+p.x, p.y)

so how i can do it? or any other idea to do the same thing?

For example

operator fun <T : Number> Int.plus(p: TestGen<T>): TestGen<Int> = 
    TestGen(this + p.x.toInt(), p.y.toInt())
1 Like

thanks @Beholder but i want to do this for all other operators plus , minus, multi … etc and for Int, Float and Double .
so when i do this , i will do it for all these types

You can’t do this completely generic. If you want to do this, you have to create pretty much duplicate methods for each number type.

1 Like

Thanks @Jonathan.Haas and @Beholder
I have got a solution in stackoverflow , you can see in this link