What does < and > mean in "List<String>"?

Anyone familiair with this line:

List<String> list =new ArrayList<String>(c)

what does the "<String>" part precisely mean? I've been through the documentation, but I've not been able to find out what those "<" and ">" represent. Now I know that brackets ("[ ]") are used for arrays, but I doubt wether it's an principal equallity.

So if someone knows its true meaning and/or has a nice URL for me to glance through some nice documentation...

Thanks in advance!

Tensos

[565 byte] By [Tensosa] at [2007-10-2 8:15:24]
# 1
Hi,Google on generics and Java 5 / Jdk 1.5. It's a new language feature.It says that the list only contains String references.Kaj
kajbja at 2007-7-16 22:13:02 > top of Java-index,Java Essentials,Java Programming...
# 2
Good Luck! :)That's part of the new Generics stuff and means something like that List will only ever contain StringSee this:- { it's over my head } http://java.sun.com/docs/books/tutorial/java/javaOO/generics.html
WIlfred_Deatha at 2007-7-16 22:13:02 > top of Java-index,Java Essentials,Java Programming...
# 3

So I see now.. it's all about Generics here.

Thanks for the URL! ... took a glance through it. And immediatly I saw a small, though true advantage of using generics; no casting required.

Now it's just a bit of getting used to the new syntax (hope Java won't get too creapy freaky coded :P) and view the conditions and rules of generics for usage.

Tensosa at 2007-7-16 22:13:02 > top of Java-index,Java Essentials,Java Programming...
# 4
> hope Java won't get too creapy freaky coded :Ptoo late, it already did
jsalonena at 2007-7-16 22:13:02 > top of Java-index,Java Essentials,Java Programming...
# 5

> too late, it already did

... seeing the code below (encountered in the general documentation), I'm afraid you're right...

Object[] toArray();

<T> T[] toArray(T[] a);

An extra functionality is fine with me, but it is a pity that it doesn't make the code more easy readible (yet).

Tensosa at 2007-7-16 22:13:02 > top of Java-index,Java Essentials,Java Programming...
# 6

> > too late, it already did

>

> ... seeing the code below (encountered in the general

> documentation), I'm afraid you're right...

>

> Object[] toArray();

> <T> T[] toArray(T[] a);

>

> An extra functionality is fine with me, but it is a

> pity that it doesn't make the code more easy readible

> (yet).

It's easy to read once you get used to it, and I don't know how they would have been able to add generics with a syntax which is easier to understand, and yet is compact.

Kaj

kajbja at 2007-7-16 22:13:02 > top of Java-index,Java Essentials,Java Programming...
# 7

> An extra functionality is fine with me, but it is a

> pity that it doesn't make the code more easy readible

> (yet).

That's still easy to read, it's when you get to things like "class Foo<E extends Comparable><? super E>>" that things get a little awry...

Kaj makes a good point, though

jsalonena at 2007-7-16 22:13:02 > top of Java-index,Java Essentials,Java Programming...
# 8
that "><" is supped to be <
jsalonena at 2007-7-16 22:13:02 > top of Java-index,Java Essentials,Java Programming...
# 9

Yeah, the code filter has been broken for generics since they last screwed up a release for the forum software.

I like generics. Writing Generified classes is the exception rather than the rule, and the type-safety of collections is pretty neat. But then I'm a heretic 'cos I like autoboxing too.

Dave.

dcmintera at 2007-7-16 22:13:02 > top of Java-index,Java Essentials,Java Programming...