Wednesday, December 26, 2012

error: generic array creation

Java does not support arrays of generic classes. A way to workaround is to use a class that implements java.util.List (ordered collection, or sequence). ArrayList is a good choice. Here is an example:

Let Vertex<E> be some generic class (on type E).
Java doesn't support:
Vertex<String> vertex = new Vertex<String>[10];


A workaround could be:
ArrayList<Vertex<String>> vertex = new ArrayList<Vertex<String>>();



No comments:

Post a Comment