Generics - where to use them?
I'm brushing up on Java 5.0, I'm at 'generics' - I always hated c++ templates and knew they would catch up with me sooner or later...
I have a fairly simple question about where and how to use them, conceptually.
Am I correct in thinking that they are primarily concerned with items containedwithin a class and passedto a class?
I'm trying to find a useful bit of code to write to practice with them and I've been half tempted to re-write something that uses lots of inheritance simply because I know the code in question needed a lot of casting, but my gut feeling is that generics doesn't have an awful lot to do with inheritance and re-jigging a class that relied on inheritance to use generics is barking up the wrong tree.
I'd really appreciate some informed comments before I go trundling off down a path that is going to end with reams of pointless code.
Thanks,
Steve
> Have a look at:
> http://blogs.sun.com/ahe/entry/selftypes
>
> I go through a concrete example explaining when and
> when not to
> parameterize a type.
Bah, what do you know? You only have a bronze star! According to your own company that indicates your level of expertise.
/sarcasm
/rant
> Bah, what do you know? You only have a bronze star!
> According to your own company that indicates your
> level of expertise.
I understand all the semantics and how they work, but as with everything in software its about where they would be used. Experience is obviously the best teacher, but I'm just trying to get some pointers before I start off.
I think my original question about whether they were relevant where inheritance has been used is the crux of what I'm asking. I've read all the documentation, I just need a few pointers about the conceptual side of things.
> > Have a look at:
> > http://blogs.sun.com/ahe/entry/selftypes
> >
> > I go through a concrete example explaining when
> and
> > when not to
> > parameterize a type.
>
> Bah, what do you know? You only have a bronze star!
> According to your own company that indicates your
> level of expertise.
>
> /sarcasm
> /rant
LOL, You tell him!
:>)
~Tim
> I understand all the semantics and how they work, but
> as with everything in software its about where they
> would be used. Experience is obviously the best
> teacher, but I'm just trying to get some pointers
> before I start off.
>
> I think my original question about whether they were
> relevant where inheritance has been used is the crux
> of what I'm asking. I've read all the documentation,
> I just need a few pointers about the conceptual side
> of things.
Then why don't you look at Peter's blog? It's not documentation, it shows usage and design, specifically with inheritance as you seem concerned about. If you don't think Peter is qualified to write on the subject then I don't know what to tell you. Angelika Langer's FAQ also addresses design, you have links to both. If those don't help then maybe be more specific?
Hopefully you didn't take my indignation seriously, the "/sarcasm" should have been enough to make the intent clear.