Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #29773
| From | Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Accessibility of suBclass-fields from suPERclass (reflection) |
| Date | 2014-08-20 18:47 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <slrnlv9rad.fp3.avl@login.logic.tuwien.ac.at> (permalink) |
| References | (5 earlier) <lsosjs$gtc$1@dont-email.me> <lsq1fh$htv$1@gregory.bnet.hr> <lsq55r$1s1$1@dont-email.me> <slrnlv1qcj.fp3.avl@login.logic.tuwien.ac.at> <53f29e2b$0$292$14726298@news.sunsite.dk> |
Arne Vajhøj <arne@vajhoej.dk> wrote: > On 8/17/2014 1:42 PM, Andreas Leitgeb wrote: >> Eric Sosman <esosman@comcast-dot-net.invalid> wrote: >>> On 8/17/2014 6:51 AM, Josip Almasi wrote: >>>> On 08/17/2014 02:22 AM, Eric Sosman wrote: >>>>> On 8/16/2014 6:37 PM, Andreas Leitgeb wrote: >>>>>> 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? >>>> Because it means coding in each subclass? >> That really is the reason. And it's not just the reset(), but also >> another bunch of methods. > > I think there are two ideas you need to consider. > 1) Make the fields in the sub classes protected instead of private. > This will allow you to avoid the setAccessible call. Actually, the fields themselves are already public. Problem was, that the subclasses appeared in contexts that weren't "accessible", such as within a statement block (as an inner class). The fields are really public final references to mutable objects, so the usual caveats about exposing public fields do not apply. > Saving a line of code is not important, but you will also get > rid of the restriction that your code will not run with a > security manager in place. That's a non-issue in my case. (But is of course good advice in the general case) > 2) Replace the reflection code in the base class with a > cast to an interface and call of method - and use AspectJ > to add interface and method implementation to all sub classes > of the base class. That's something I'll have get into, some day... Until I really understand that aspect-stuff, I'm kind of suspicious of it ;) The separation between business and framework already exists: the base class is framework, whereas the subclasses with their fields are business :) I've got a plan B, too, that would avoid reflection, but that involves overriding a method to return an array of all the referenced objects in each subclass. I happily avoid that as long as reflection and setAccessibility work well enough for me.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Accessibility of suBclass-fields from suPERclass (reflection) Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-08-15 00:58 +0000
Re: Accessibility of suBclass-fields from suPERclass (reflection) Lew <lewbloch@gmail.com> - 2014-08-15 15:20 -0700
Re: Accessibility of suBclass-fields from suPERclass (reflection) Steven Simpson <ss@domain.invalid> - 2014-08-16 00:11 +0100
Re: Accessibility of suBclass-fields from suPERclass (reflection) Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-08-16 00:10 +0000
Re: Accessibility of suBclass-fields from suPERclass (reflection) Arne Vajhøj <arne@vajhoej.dk> - 2014-08-15 23:26 -0400
Re: Accessibility of suBclass-fields from suPERclass (reflection) Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-08-16 08:46 +0000
Re: Accessibility of suBclass-fields from suPERclass (reflection) Robert Klemme <shortcutter@googlemail.com> - 2014-08-16 12:27 +0200
Re: Accessibility of suBclass-fields from suPERclass (reflection) "Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org> - 2014-08-16 13:37 +0100
Re: Accessibility of suBclass-fields from suPERclass (reflection) Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-08-16 09:47 -0400
Re: Accessibility of suBclass-fields from suPERclass (reflection) Robert Klemme <shortcutter@googlemail.com> - 2014-08-17 13:19 +0200
Re: Accessibility of suBclass-fields from suPERclass (reflection) Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-08-16 22:37 +0000
Re: Accessibility of suBclass-fields from suPERclass (reflection) Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-08-16 20:22 -0400
Re: Accessibility of suBclass-fields from suPERclass (reflection) Josip Almasi <joe@vrspace.org> - 2014-08-17 12:51 +0200
Re: Accessibility of suBclass-fields from suPERclass (reflection) Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-08-17 07:54 -0400
Re: Accessibility of suBclass-fields from suPERclass (reflection) "Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org> - 2014-08-17 13:44 +0100
Re: Accessibility of suBclass-fields from suPERclass (reflection) Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-08-17 17:42 +0000
Re: Accessibility of suBclass-fields from suPERclass (reflection) Arne Vajhøj <arne@vajhoej.dk> - 2014-08-18 20:45 -0400
Re: Accessibility of suBclass-fields from suPERclass (reflection) Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-08-20 18:47 +0000
Re: Accessibility of suBclass-fields from suPERclass (reflection) Josip Almasi <joe@vrspace.org> - 2014-08-18 17:19 +0200
Re: Accessibility of suBclass-fields from suPERclass (reflection) Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-08-17 18:04 +0000
Re: Accessibility of suBclass-fields from suPERclass (reflection) Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-08-17 15:24 -0400
Re: Accessibility of suBclass-fields from suPERclass (reflection) Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-08-17 21:35 +0000
Re: Accessibility of suBclass-fields from suPERclass (reflection) Josip Almasi <joe@vrspace.org> - 2014-08-16 12:31 +0200
Re: Accessibility of suBclass-fields from suPERclass (reflection) Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-08-16 10:51 -0400
Re: Accessibility of suBclass-fields from suPERclass (reflection) Arne Vajhøj <arne@vajhoej.dk> - 2014-08-16 11:00 -0400
csiph-web