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

[942 byte] By [Steve12345a] at [2007-11-26 13:02:39]
# 1
http://java.sun.com/j2se/1.5/pdf/generics-tutorial.pdf
aniseeda at 2007-7-7 17:05:59 > top of Java-index,Java Essentials,Java Programming...
# 2
This might be useful: http://java.sun.com/j2se/1.5/pdf/generics-tutorial.pdf
prometheuzza at 2007-7-7 17:05:59 > top of Java-index,Java Essentials,Java Programming...
# 3
You might want to move this post to the Generics forum, under the Core API. There are a lot of posters there that can probably better answer the question. Not that there aren't any here :)~Tim
SomeoneElsea at 2007-7-7 17:05:59 > top of Java-index,Java Essentials,Java Programming...
# 4
Hi,I have used generics a lot when working with collections framework. They reduce type-casting and the code becomes easier to understand.
ashadia at 2007-7-7 17:05:59 > top of Java-index,Java Essentials,Java Programming...
# 5
Have a look at: http://blogs.sun.com/ahe/entry/selftypesI go through a concrete example explaining when and when not toparameterize a type.
PeterAhea at 2007-7-7 17:05:59 > top of Java-index,Java Essentials,Java Programming...
# 6

> 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

kablaira at 2007-7-7 17:05:59 > top of Java-index,Java Essentials,Java Programming...
# 7

> 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.

Steve12345a at 2007-7-7 17:05:59 > top of Java-index,Java Essentials,Java Programming...
# 8

> > 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

SomeoneElsea at 2007-7-7 17:05:59 > top of Java-index,Java Essentials,Java Programming...
# 9

> 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.

kablaira at 2007-7-7 17:05:59 > top of Java-index,Java Essentials,Java Programming...