I am trying to make a Graph class with generic vertices and adjacency lists and I am getting a generic array creation error at line 10 of the following code. Earlier I was getting the same error at line 11 but it was solved by casting. But this error remains. What is wrong in the code?
import java.util.HashSet;
public class Graph<T> {
private int numVertices;
private T[] vertex;
private HashSet<T>[] adjacent;
public Graph(int numVertices) {
this.numVertices = numVertices;
vertex = (T[]) new T[numVertices];
adjacent = (HashSet<T>[]) new HashSet[numVertices];
}
}