Should an adapter have access to protected
fields of its adapted type?
#4560
Labels
design idea
An issue recording a specific language design idea that folks can potentially pick up.
long term
Issues expected to take over 90 days to resolve.
Should this be valid:
On the one hand, adapting a class is somewhat like inheritance, so perhaps an adapter should be able to access protected fields. On the other hand, adapting a class is not inheritance in various ways. Note that
A
is a final class; if it inheriteda
from one of its base classes, it may not expect that any code outsideA
and its base class can access that field. (Maybe we might even want to rejectprotected
members in final classes.)If we don't allow this, one could still use
friend
declarations to allow specific adapters to access non-public class members. The design currently doesn't permit adapters to access protected members of the adapted type; this came up because the toolchain currently does (though we plan to change it to match the current design).The text was updated successfully, but these errors were encountered: