0

I am declaring a LinkedList of LinkedLists of type GraphEdge as follows:

First declare LinkedList and fixed length (for global numVertices):

LinkedList[] adjList = new LinkedList[numVertices];

Then initialize each adjList[i] as a new LinkedList<GraphEdge>()

for (i = 0; i < this.numVertices; i++) {
    adjList[i] = new LinkedList<GraphEdge>();
}

But I am getting an error when trying to call:

GraphEdge nextEdge = adjList[v].peekFirst();
1
  • 2
    That is not a LinkedList of LinkedLists - it's an array of LinkedLists. Commented Oct 25, 2015 at 20:04

1 Answer 1

1

Use a LinkedList<LinkedList<GraphEdge>> instead of an array to preserve the generic type information or add a cast.

GraphEdge nextEdge = (GraphEdge)adjList[v].peekFirst();

The cast is the ugly, bad solution.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.