0

When creating a LinkedList with this statement in Java

LinkedList<Integer> adj[] = new LinkedList[numPlaces()];

I get two warnings saying

RoadMap.java:247: warning: [rawtypes] found raw type: LinkedList
                        LinkedList<Integer> adj[] = new LinkedList[numPlaces()];
                                                        ^
  missing type arguments for generic class LinkedList<E>
  where E is a type-variable:
    E extends Object declared in class LinkedList
RoadMap.java:247: warning: [unchecked] unchecked conversion
                        LinkedList<Integer> adj[] = new LinkedList[numPlaces()];
                                                    ^
  required: LinkedList<Integer>[]
  found:    LinkedList[]
2 warnings

The code runs the way it is inteded to but what do I need to change to solve them?

biner1999
  • 35
  • 4
  • There is no great reason to create an array of generic elements. Use a `List>`. (Also, you almost certainly don't really want to be using `LinkedList`: even Josh Bloch, who *wrote* `LinkedList`, questions its usefulness). – Andy Turner Feb 06 '20 at 22:54
  • Also: don't use the `Type variable[]` to declare an array: put the `[]` with the type, like `Type[] variable`. (The two forms are equivalent, but Java style strongly prefers the second way) – Andy Turner Feb 06 '20 at 22:56

0 Answers0