Can Java nest generics? The following is giving me an error in Eclipse:
ArrayList<ArrayList<Integer>> numSetSet = ArrayList<ArrayList<Integer>>();
The error is:
Syntax error on token "(", Expression expected after this token
Can Java nest generics? The following is giving me an error in Eclipse:
ArrayList<ArrayList<Integer>> numSetSet = ArrayList<ArrayList<Integer>>();
The error is:
Syntax error on token "(", Expression expected after this token
That should be:
ArrayList<ArrayList<Integer>> numSetSet = new ArrayList<ArrayList<Integer>>();
Or even better:
List<List<Integer>> numListList = new ArrayList<List<Integer>>();
List<ArrayList<Integer>> numSetSet = new ArrayList<ArrayList<Integer>>();List<List<Integer>> numListList = new ArrayList<List<Integer>>(); compiles just fine on my machine.List interface easily without changing lots of code.And here are some slightly tricky technic about Java template programming, I doubt how many people have used this in Java before.
This is a way to avoid casting.
public static <T> T doSomething(String... args)
This is a way to limit your argument type using wildcard.
public void draw(List<? extends Shape> shape) {
// rest of the code is the same
}
you can get more samples in SUN's web site:
http://java.sun.com/developer/technicalArticles/J2SE/generics/
You forgot 'new' keyword as in below code:
ArrayList<ArrayList<Integer>> numSetSet = new ArrayList<ArrayList<Integer>>();
You can also use Maps along with Lists for nested Generics as shown in Java 5 (J2SE 5.0/JDK 1.5) New Features with Examples