0

I really don't get the meaning of E in this interface. I have been searching but no luck so far. Can someone pls explain it.

public interface MyList<E> {
    int getSize();
    void insert(MyList<?> data) throws ListOverflowException;
    E getElement(E data) throws NoSuchElementException;
    boolean delete(E data); // returns false if the data is not deleted in the list
    boolean search(E data);
}
Zabuzard
  • 25,064
  • 8
  • 58
  • 82
  • Its a generic. So the user, who implements this interface, can choose a type. `E` itself is a placeholder for the type. For example, a class could do `class StringList implements MyList { ... }`. Id suggest you lookup a tutorial about generics. – Zabuzard Aug 24 '21 at 13:04
  • There is an issue at the `insert` method. It shouldnt take `MyList> data` but `MyList extends E> data`. Otherwise its unsafe. Remember **PECS**. – Zabuzard Aug 24 '21 at 13:06
  • The `getElement` method seems odd to me. It should probably take an index instead, so `E getElement(int index)`. Or should be changed to a `contains` method like `boolean contains(E element)`. – Zabuzard Aug 24 '21 at 13:09
  • See [Lesson: Generics](https://docs.oracle.com/javase/tutorial/java/generics/index.html) in Oracle's Java Tutorials. – Jesper Aug 24 '21 at 13:10
  • Thank you for the answer. Got it lemme revise seems like I revised the insert method by mistake. Well, this code was from my programming assignment. – Julliard - Kun Aug 24 '21 at 13:13

0 Answers0