0

I'm trying to implement a simple linked list using Java's LinkedList class but cannot seem to get the compiler to identify the LinkedList methods.

Some simple test code:

import java.util.*;
public class Test {
    public static void main(String[] args) {
        LinkedList ll = new LinkedList();
        ll.add(1);
  }
}

This results in the following error:

Test.java:6: error: cannot find symbol
    ll.add(1);
      ^
  symbol:   method add(int)
  location: variable ll of type LinkedList
1 error

I'm sure I'm making some simple mistake but I can't for the life of me seem figure it out on my own. Thanks for any help.

Reed Boyer
  • 21
  • 5
  • If you were using `java.util.LinkedList` you'd be using it as a [raw type](http://stackoverflow.com/q/2770321/113632), which is a bad idea. Properly declaring your list's type and avoiding raw types would have made this issue obvious. – dimo414 Jul 22 '16 at 03:10

1 Answers1

3

You've got your own class named LinkedList and it's confusing the compiler. Rename that class to anything else, as long as your new name doesn't clash with the core Java classes as yours currently does.

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373