Reputation: 91
I'm trying to implement a Graph as an adjacency list, with the code below. I'm getting a raw type error on line 9.
Edit: Just want to clarify, I get an unchecked/unsafe operation error, then when I compile with Xlint, I get the raw type error.
import java.util.LinkedList;
public class AdjListGraph{
private int vertices;
private LinkedList<Integer>[] AdjList;
public AdjListGraph(int v){
this.vertices = v;
AdjList = (LinkedList<Integer>[]) new LinkedList[v];
for (int i = 0; i < v; i++){
AdjList[i] = new LinkedList<Integer>();
}
}
Upvotes: 0
Views: 70
Reputation: 37916
LinkedList<Integer>[]
is a bad smell.
And that's the real problem. You can't have arrays of generic classes. Java simply doesn't support it. Read more in Q: How to create a generic array in Java?.Upvotes: 1