Is it even possible to create a method reference t...
# announcements
i
Is it even possible to create a method reference to such a function?
Copy code
public operator fun T.minus(b: T): T = add(this, -b)
1
d
Yes, but you have to decide on what
T
should be beforehand:
Copy code
public operator fun <T> T.minus(b: T): T = add(this, -b)

val ref = String?::minus
val ref2 = Any?::minus
val ref3 = SomeClass::minus
These all work and all point to the same function, with
T
being
String?
,
Any?
and
SomeClass
respectively.
r
I assume
T
in the original was a concrete type, not a generic one - otherwise
unaryMinus
wouldn’t resolve.