Where and when to use generics?

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 contained within a class and passed to 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

[928 byte] By [Steve12345a] at [2007-11-26 13:03:11]
# 1
A continuation of this post: http://forum.java.sun.com/thread.jspa?threadID=5117359&messageID=9404277#9404277
ChuckBinga at 2007-7-7 17:07:21 > top of Java-index,Core,Core APIs...
# 2

IMO the most useful feature of using Generics is compile time typesafety.

Consider the pre-1.5 code for making a LinkedList that contains strings:

LinkedList l = new LinkedList();

l.add("Hello world!");

l.add(new Integer(100));// <- runtime exception

Instead, you can now write the code like this:

LinkedList<String> l = new LinkedList<String>();

l.add("Hello world!");

l.add(new Integer(100));// compile time exception

If you accidentally put the wrong type in a Collection you will get a nice compile time exception instead of a ClassCastException at runtime.

Strider80a at 2007-7-7 17:07:21 > top of Java-index,Core,Core APIs...