2.6 Using Parameterized Types as Type Parameters
Collections in Tiger are generic types, and accept type parameters. However,
these collections can store collections themselves, which are in turn
also generics. This means that a parameterized type can be used as the
type parameter to another generic type.
2.6.1 How do I do that?
The Map interface takes two type parameters: one for the key, and one for
the value itself. While the key is usually a String or numeric ID, the
value can be anythingincluding a generic type, like a List of Strings.So List<String> becomes a parameterized type, which can be supplied
to the Map declaration:
Map<String, List<String>> map = new HashMap<String, List<String>>( );If that's not enough angle brackets for you, here's yet another layer of
generics to add into the mix:
Map<String, List<List<int[]>>> map = getWeirdMap( );Of course, where things get really nuts is actually accessing objects from
this collection:
int value = map.get(someKey).get(0).get(0)[0];What's cool about this is that all the casting is handled for youyou don't
need to do any casting to List, but instead can just let the compiler
unravel all your parameterized types for you.