Dico
09/06/2018, 9:47 AMthis
instance at all.
It is obviously not feasible to replace existing behaviour with a new one - where the expression is evaluated on each call. Thus, a new syntax needs to be come up with to distinguish between the two. Current ideas, where B is an interface:
• class A : B by val foo {
val foo : B = ...
}
• class A : B {
val foo : B = ...
delegate B to foo
}
• class A : B by ::foo {
val foo : B = ...
}
• class A : B {
@Delegates(B::class)
val foo: B = ...
}
Please share any ideas you have for a better syntax, or why you think one is better! The behavioural difference between the old and new syntax must be obvious.
I am also considering proposing a compiler-intrinsic inline fun <reified T : Any> delegate(): T
function which would simply emit code that gets the delegate used for the given type under the hood (for delegating methods). There are some issues with this declaration - would love to hear opinions.
Have a look at [KT-83](https://youtrack.jetbrains.com/issue/KT-83) for background.
EDIT: In [this gist](https://gist.github.com/Dico200/0065293bcd9a19c50e371cde047a9f22) we can discuss and make changes to the KEEP before it's submitted as a PR in the [KEEP repository](https://github.com/Kotlin/KEEP)