<@U3T6LDWTD> That would break encapsulation, no?
# language-proposals
k
@benleggiero That would break encapsulation, no?
b
I suppose I think of extensions differently than most
k
@benleggiero In the end
fun T.func()
is just synthetic sugar for
fun func(this: T)
.
r
@benleggiero The docs are very clear that extension functions are resolved statically. It's nice to think that extension functions add functionality into a class, but it's important to remember the distinction.
b
Right, but at compile time, the compiler sees everything. Scope is just for the coder, and the compiler can break scope all it wants. In this example, the compiler would just treat the
protected
field as
internal
solely for the extension function, but still as
protected
everywhere else. This should work out just fine, since the visibility from 3rd party code is unaffected. It's just exposing to the extension function the same capabilities a subclass would have, and extensions are (partially) a replacement for "utility" subclasses.