Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What arguments should add function accept for generic set<E> in java?

Tags:

java

I am trying to write a Set<E> interface in Java, that will be implemented by another class mySet<E> utilising an arrayList<E> to store the elements.

I intend to include regular set functions: add(), remove(), union() intersection() etc.

What should the type be for my add() and remove() functions? I have tried using add(Object E) and add(<E>) but am running into errors.

like image 490
Massin Avatar asked Oct 30 '22 23:10

Massin


1 Answers

add(E objToAdd);
remove(E objToRemove);

Reference - Generics In Java

like image 83
Matteo Rubini Avatar answered Nov 15 '22 06:11

Matteo Rubini