Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #35388
| From | Robert Klemme <shortcutter@googlemail.com> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Generics |
| Date | 2016-08-18 08:23 +0200 |
| Message-ID | <e1l2iaFpk2aU1@mid.individual.net> (permalink) |
| References | <681a67de-8a78-46ab-a028-5176a48df402@googlegroups.com> <np2dhf$tvo$1@dont-email.me> <2ce12c5a-fdb0-43ad-b4a3-4ffc28836df3@googlegroups.com> |
On 17.08.2016 23:03, Eric Douglas wrote: > On Wednesday, August 17, 2016 at 3:22:32 PM UTC-4, Eric Sosman > wrote: >> However, I'd view this need with suspicion. The "instanceof" >> operator (and its reflective counterparts) are often signs that the >> design should be reconsidered -- and perhaps retained, but only >> after due thought has lowered the raised eyebrows. More commonly, >> it's a sign that polymorphism is not being used to best advantage. > > This seemed like a separate topic for a new thread but in this case > is related to the XML. As the design states, TestA is just a wrapper > class. It holds a variable that is a List<E> which may contain > anything which extends TestB which may be TestC, or TestD, etc. I > want each instance of TestA to be able to marshal itself which > requires knowing the specific classes of TestC, etc. but I want to > hide the marshalling so the instance of TestA only has to tell it > that class name once. That does not seem to make sense - or I am misunderstanding you. Depending on the contents of the List there may be any number of classes (including zero). You would need the type per entry in the list and then you can just ask the individual object via getClass(). Main question is, what is that type used for? As has been suggested the OO solution would be to have all classes implement their own marshalling (see how custom serialization works). If that cannot be done because marshalling is supposed to be a separate aspect then you can have a Map<Class<? extends E>,Marshaller> to attach additional functionality to these classes. > So I'm using a method to pass in the class > name because TestA is the root object for this XML so adding a > parameter to the constructor gets ugly.. What about JAXB? Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Generics Eric Douglas <e.d.programmer@gmail.com> - 2016-08-17 11:59 -0700
Re: Generics Marcel Mueller <news.5.maazl@spamgourmet.org> - 2016-08-17 21:20 +0200
Re: Generics Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-08-17 15:22 -0400
Re: Generics Eric Douglas <e.d.programmer@gmail.com> - 2016-08-17 14:03 -0700
Re: Generics Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-08-17 20:06 -0400
Re: Generics Robert Klemme <shortcutter@googlemail.com> - 2016-08-18 08:23 +0200
Re: Generics Eric Douglas <e.d.programmer@gmail.com> - 2016-08-18 05:34 -0700
csiph-web