Relates :
|
|
Relates :
|
|
Relates :
|
A DESCRIPTION OF THE REQUEST : Consider the following piece of code: List<Map<String,List<Integer>>> list = new ArrayList<Map<String,List<Integer>>>(); One has to repeat type parameters twice (and they can be even longer than in this example). This kind of repetition of type arguments is bug-prone and creates unnecessary clutter in the code. One shall be able to write this code simpler, like this: List<Map<String,List<Integer>>> list = new ArrayList(); JUSTIFICATION : For ease of development. EXPECTED VERSUS ACTUAL BEHAVIOR : EXPECTED - The proposed code shall compile normally via type parameter inference mechanism. ACTUAL - This code complies, but produces unchecked warnings. ---------- BEGIN SOURCE ---------- import java.util.*; public class ListCreate { public static void main(String[] args) { List<Map<String,List<Integer>>> list = new ArrayList(); } } ---------- END SOURCE ---------- CUSTOMER SUBMITTED WORKAROUND : Use static factory methods instead of constructors. They work just fine with type argument inference without any warnings. import java.util.*; public class ListCreate2 { public static void main(String[] args) { List<Map<String,List<Integer>>> list = newArrayList(); } public static <T> ArrayList<T> newArrayList() { return new ArrayList<T>(); } } ###@###.### 2005-1-24 13:16:39 GMT
|