First of all i have little experience in Java.
Getting to my question, I am implementing my own list with my own methods.
public class MyList<E> implements List<E>{
private Node<E> head;
private static class Node<E> {
private E element;
.....
}
Now, there is a method in this class that compares this list with a given one:
public boolean equals(List<E> list){
....
}
To start this method, first we would have to get list's head, so afterward i can access element and compare the list.
Now, we don't have a getHead() method.
So, we tried creating the following method in the implementing class
public Node<E> getHead(){
The compiler does not find the symbol. Of course, we need to declare it first in the interface. The problem is, if we try to do it, interface does not know what Node is. So i am in a deadlock here.
I get the error:
Cannot find symbol
symbol : method getHead()
location: interface List<E>
Node<E> lhead = list.getHead();
What i want it to make getHead a implementation-specific method. How do i do that?
I ask, can we move the internal class in the implementing to the interface? Have no idea how to solve this issue,
thanks for your time
getHead()returnE?headis an instance ofNode<E>sogetHeadshould returnNode<E>, no?public boolean equals(List<E> list){Usually equals method doesn't look like that. The parameter type isObject. It overloads the methodpublic boolean equals(Object object){. Try with an@Overrideannotation.