Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Eric Sosman Newsgroups: comp.lang.java.programmer Subject: Re: Accessibility of suBclass-fields from suPERclass (reflection) Date: Sat, 16 Aug 2014 20:22:16 -0400 Organization: A noiseless patient Spider Lines: 35 Message-ID: References: <53eecf6a$0$300$14726298@news.sunsite.dk> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sun, 17 Aug 2014 00:22:21 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="bd4e1cba8d8592bec5d5ed9e4537fbfd"; logging-data="17324"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19ysSZLNhldiy8Dl3DXkkQw" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.0 In-Reply-To: Cancel-Lock: sha1:ht7mKwI0nm53PkYLLZPTY0tU+Ro= Xref: csiph.com comp.lang.java.programmer:29701 On 8/16/2014 6:37 PM, Andreas Leitgeb wrote: > Robert Klemme wrote: >> On 16.08.2014 10:46, Andreas Leitgeb wrote: >>> 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. > >> 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. > > I'll describe my situation a bit: > > I have a special Base class, and each of its subclasses serve exactly > one purpose: a collection of name/value associations where the java- > compiler knows about the valid names, so as to detect accesses to > non-existing names already at compile-time. (without that last premise, > I would have used HashMaps instead of subclasses) Would an EnumMap serve? > Overall-operations, (e.g. resetting all values of a given subclass > instance) are done from Base-class by use of reflection. Why by reflection? Why not by a reset() method, abstract in the superclass? I'm confident you have reasons, but I'm sure I haven't yet grasped them. -- esosman@comcast-dot-net.invalid