Reference properties using `by`, `is`, or somethin...
# language-proposals
h
Reference properties using
by
,
is
, or something like that current:
Copy code
var foo = 3

var bar
    get() = foo
    set(v) {
        foo = v
    }
proposed:
Copy code
var foo = 3
var bar by foo
1
3
d
This is ambiguous, since this currently means "use the value of
foo
as a delegated property", not "delegate to `foo`"
What would be nice though is
var bar by ::foo
👍 4
i
d
Yes, but it would be nice for this to be optimized by the compiler.
s
What would be optimized? Seems like you could make
Alias
from the github link
inline
even. I wouldn't complicate the compiler nor the language for something that you can so elegantly solve in the language already.
1
d
seems you are right, this works nicely:
Copy code
operator fun <T, R> KProperty1<T, R>.getValue(thisRef: T, prop: KProperty<*>): R = get(thisRef)
operator fun <T, R> KMutableProperty1<T, R>.setValue(thisRef: T, prop: KProperty<*>, newValue: R) = set(thisRef, newValue)
Should be able to be optimized by the JVM
h
@diesieben07 shame though that your solution, while elegant, cannot be used an interface (because no delegation in interfaces), while the
getter
setter
version does
k