I have an interface called ListInterface<T> that has the method join:
public interface ListInterface<T> {
/**
* Join a new list to the original list.
* @param otherList The new list to be joined.
* @return Original list with appended part from the new list.
* @throws IllegalArgumentException.
*/
public ListInterface<T> join(ListInterface<T> otherList) throws IllegalArgumentException;
}
Two classes DoubleLinkedList and MyArrayList implement this interface.
So in DoubleLinkedList, I need to write join like this:
public ListInterface<T> join(DoubleLinkedList<T> otherList) throws IllegalArgumentException {
(...)
}
And in MyArrayList:
public ListInterface<T> join(MyArrayList<T> otherList) throws IllegalArgumentException {
(...)
}
But this is not possible and the type of arguments must be ListInterface<T>. If I change the method signatures in these classes to public ListInterface<T> join(ListInterface<T> otherList), then I can't use other specific methods on DoubleLinkedList or MyArrayList anymore. How should I change the method signature in ListInterface in order to fix this?