i want to add aliases property to some class in kotlin which just delegate themselves to some existed properties
then i invent a method called alias to do so, which unfortunately results in an Exception
val <T> Array<T>.length by alias(Array<T>::size)
val <T> Collection<T>.length by alias(Collection<T>::size)
fun <R, T> alias(alias: KProperty1<R, T>) = object : ReadOnlyProperty<R, T> {
override operator fun getValue(thisRef: R, property: KProperty<*>): T {
return alias.get(thisRef)
}
}
following the exception stack
java.lang.NoSuchMethodError: [Ljava.lang.Object;.getSize()I
at kt.ruby.ArrayKt$length$2.get(Array.kt:34)
at kt.ruby.ArrayKt$alias$1.getValue(Array.kt:40)
at kt.ruby.ArrayKt.getLength(Array.kt)
Aucun commentaire:
Enregistrer un commentaire