Change your declaration to
public class MyLinkedList extends LinkedList<String>
By adding <String>
to your MyLinkedList
class name you create a new type parameter whose name shadows the real class String
.
Question
I'm trying to extend the LinkedList class but i'm getting a strange error, whenever i try to add an accessor class that returns a string i get the error
found : java.lang.String required: String
I cant work out why this is happening. (I'm pretty new to linked lists and java in general, be nice :) )
import java.util.*;
public class MyLinkedList<String> extends LinkedList<String>
{
private int count; //for future use
public void MyLinkedList()
{
count = 0;
}
public boolean add(String s)
{
boolean x = super.add(s);
count++;
return x;
}
public String toString()
{
return("test");
}
}
Solution
Change your declaration to
public class MyLinkedList extends LinkedList<String>
By adding <String>
to your MyLinkedList
class name you create a new type parameter whose name shadows the real class String
.