What is the difference between a Class
and a Class>
declaration.
Class a;
Class> b;
>
"it look like old code or code written by someone who hasn't learned generics yet." This is an correct statement. Class (pronounced "class of unknown"), that is, a class whose type matches anything. It's called a wild-card type for obvious reasons.
for example:
public void drawAll(List shapes) {
for (Shape s: shapes) {
s.draw(this);
}
}
type rules say that drawAll() can only be called on lists of exactly Shape
: it cannot, for instance, be called on, say, a List
. That is unfortunate, since all the method does is read shapes from the list, so it could just as well be called on a List
.
What we really want is for the method to accept a list of any kind of shape.
public void drawAll (List extends Shape> shapes) {
}
read more: http://docs.oracle.com/javase/tutorial/extra/generics/wildcards.html