martmists
05/15/2022, 11:44 PMclass BaseType {
val someProp: Int = 10
}
fun handleProperty(prop: KProperty1<BaseType, Int>) {
// get BaseType instance here somehow
}
fun main() {
val x = BaseType()
handleProperty(x::someProp)
}
ephemient
05/16/2022, 12:52 AMKProperty1
is an unbound member property, so it doesn't have an instance. if you bind it to an instance, you get a KProperty0
, but that doesn't expose the instance - KProperty0
can also be a top-level (non-member) property.this
ref is passed separatelymartmists
05/18/2022, 9:05 AMclass X {
val in1 by input()
val out1 by output()
fun connect(output: String, node: X, input: String) { ... }
}
fun main() {
x1 = X()
x2 = X()
x1.connect("out1", x2, "in1")
}
// ideally:
fun main() {
x1 = X()
x2 = X()
x1::out1 connectsTo x2::in1 // connectsTo is an infix fun taking both properties but has access to the property owners
}