I am not to sure if this works. It compiles just fine but is this the correct way to use generics?
The assignment says "Write a generic method numberOf that takes an element and a list and returns the number of times the element appears in the list. Note the element may be of different type than the type of the entries in the list."
package listUtilities;
import utilities.containers.*;
public class ListUtil<E extends Comparable>{
/**
* Returns the number of times a generic element appears in the list.
*/
public static <E> int numberOf(E element, List<? extends Comparable> list){
int n = 0;
for(int i = 0;i<list.size();i++){
if ((list.get(i).getClass()).equals(element.getClass()) //check class equality
&&list.get(i).compareTo(element)==0) //check value equality
n++;//increment counter
}
return n;
}//end of numberOf
}//end of class ListUtil