Property and function references currently look something like this
ClassWithLongName::propertyWithLongName
It would be useful to have a short-hand property/function reference where the receiver is already known. Take for example the following example, where the receiver is declared at the class level:
class Foo<T> {
fun <P> getPropertyName(property: KProperty<T, P>): String {
return property.name
}
}
val foo = Foo<ClassWithLongName>()
val propertyName = foo.getPropertyName(ClassWithLongName::propertyWithLongName)
Note that whilst ClassWithLongName
is declared by the Foo
class’s generic type parameter, ClassWithLongName
still has to be specified in order to obtain a reference to ::propertyWithLongName
It seems unnecessary to have to specify it twice, when T
of KProperty<T, P>
is already known.
Shorthand would allow syntax something like this:
val foo = Foo<ClassWithLongName>()
val propertyName = foo.getPropertyName(::propertyWithLongName)
Any thoughts as to whether this could become part of a future Kotlin language spec?