In this code:
public interface LinkedList<T> {
<N extends Node<T>> Optional<N> findNodeByData(T data);
// ...
}
public class SinglyLinkedListNode<T> extends Node<T> {
// ...
}
public class Node<T> {
// ...
}
public class SinglyLinkedList<T> implements LinkedList<T> {
public Optional<SinglyLinkedListNode<T>> findNodeByData(T data){
// ...
}
}
My goal is to have the method in interface accept any class that extends Node<T>
, as N
.
I get the error 'findNodeByData(T)' in 'com.starosti.datastructures.linkedlist.singly.SinglyLinkedList' clashes with 'findNodeByData(T)' in 'com.starosti.datastructures.linkedlist.LinkedList'; both methods have same erasure, yet neither overrides the other
in the line that findNodeByData
is defined in SinglyLinkedList<T>
.
How do I fix this issue? Is there a better way to do this?