Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news-1.dfn.de!news.dfn.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Robert Klemme Newsgroups: comp.lang.java.programmer Subject: Re: Accessibility of suBclass-fields from suPERclass (reflection) Date: Sat, 16 Aug 2014 12:27:58 +0200 Lines: 32 Message-ID: References: <53eecf6a$0$300$14726298@news.sunsite.dk> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net hCzWczkyNGitARQw4ymONA9BDKcw7RE9QfwvfTG+HSKoNj7M4= Cancel-Lock: sha1:DqovTHGasyqVDCBzezFbaQwpt4Y= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.0 In-Reply-To: Xref: csiph.com comp.lang.java.programmer:29692 On 16.08.2014 10:46, Andreas Leitgeb wrote: > Consistent maybe, but why cannot Base access these fields by default? > > I'm not complaining about that extra setAccessibility(true), I just > would like to see an example of where a Base-class accessing its children > could be a security issue. I'm not talking of some arbitrary class > attempting access, but about the target class's parent (or grandparent) > class. > > I'm probably unaware of some risk, and learning about it was my reason > for the posting. If I understand your issue correctly: this is not about security but about design principles. Dependency always goes up the inheritance chain - not downwards. Meaning, all subclasses have knowledge about their superclasses but not vice versa. If you want a superclass to access subclass state you need to provide means for it, e.g. defining abstract accessor or other methods in the base class which then must be implemented in subclasses. There are languages out there that handle this differently. For example, in Ruby instance variables are immediately accessible for all instance methods - regardless of their defining class. But then again, Ruby has a quite different approach to visibility and accessibility. Kind regards robert