My previous proposal (two messages up) is not poss...
# language-proposals
l
My previous proposal (two messages up) is not possible because it could lead to initialization issues. I was thinking about adding enclosing braces (
class SomeClass : CharSequence by { privateWrapper.text }
, but I know it would clash with functional types… then I thought about this: If I had to choose between interface implementation by delegation to an expression, and function type implementation by delegation, what would I pick? Of course I'd pick former! Why? Because it allows to implement multiple methods at once, while the latter only implements one method with an expression: meh. I can do it with override, it's not really longer. So, what about deprecating implementation of function interfaces by delegation with the current syntax, to allow supporting the following code in the future?
Copy code
class CharSequenceWrapper(val text: CharSequence)

class SomeClass : CharSequence by { privateWrapper.text } { // The expression is evaluated each time
    private val privateWrapper = CharSequenceWrapper("Hello!")
}