Johann Pardanaud
06/18/2023, 8:43 PMclass Wrapper<T>(val wrappedValue: T, parent: Wrapper<*>? = null)
fun <T : Any?, V> Wrapper<T>.wrapperOf(getter: KProperty1<T & Any, V>): Wrapper<V?> {
return Wrapper(wrappedValue?.let { getter.get(it) }, this)
}
fun main() {
// does not compile
Wrapper("foo" as String?).wrapperOf(String::length)
// but compiles with an intermediate variable
val getter = String::length
Wrapper("foo" as String?).wrapperOf(getter)
}
Link to the playground
If I comment the eleventh line, it compiles, despite using nearly the same code just below but with an intermediate value.
What do you think? Am I missing something?Johann Pardanaud
06/18/2023, 9:31 PMWrapper("foo" as String?).wrapperOf(String::length as KProperty1<String, Int>)
Jacob
06/18/2023, 9:47 PMYoussef Shoaib [MOD]
06/18/2023, 10:08 PMYoussef Shoaib [MOD]
06/18/2023, 10:16 PMT & Any
.Johann Pardanaud
06/19/2023, 11:16 AMJohann Pardanaud
06/19/2023, 11:17 AMJohann Pardanaud
06/19/2023, 11:56 AM