tags:

views:

131

answers:

4

In Java (5+) you can do:

TreeMap<String, List> map = someObject.getMap();

But can specify the generic type within the List? A la:

TreeMap<String, List<String>> map = someObject.getMap();

??

+2  A: 

Yes you can. Do you have a compiler error in your code you want help fixing?

TofuBeer
+2  A: 

Yes,why not? But keep in mind that the type gets erased in the compiled code, so isn't runtime available. That can be a problem if you access it with reflection.

extraneon
+4  A: 

You sure can. Works great.

Electrons_Ahoy
+3  A: 

You can nest generic types to arbitrary number of levels. E.g :

 TreeMap<String, List<Map<String, String>>>
fastcodejava