So I'm writing my own simplified LinkedList class. When I compile my code I receive this error

Error: F:\Files\ICS\Card\LinkedList2.java:3: name clash: indexOf(E) in LinkedList2<E> and indexOf(java.lang.Object) in java.util.AbstractList<E> have the same erasure, yet neither overrides the other

The code is

public int indexOf (E element)
  {
    Link<E> o = new Link<E>();
    for (int i = 0; i<size; i++)
    {
      o = getElement(i);
      if (o.data.equals(element))
        return i;
    }
    return -1;
  }

and the LinkedList class header is

public class LinkedList2<E> extends AbstractSequentialList<E>

My guess is that you need to override indexOf(Object obj); Post your code including the imports.

Does it work if you change the name of your method to something else besides indexOf ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.