I have a java assignment where i am supposed to construct a class that works like a Multiset. The class has to implement the interface Collections. I have tried to do this and declare all the methods that are in Collections (found here). But when i compile this code I get the following error:
error: TreeMultisetNy is not abstract and does not override abstract method retainAll(Collection<?>) in Collection
Why is this happening?
Heres my code:
import java.util.*;
public class TreeMultisetNy<E extends Comparable<E>> implements Collection<E> {
private Map<E, Integer> data = new TreeMap<E, Integer > ();
public boolean add(E ny) {
return true;
}
public boolean addAll(Collection<? extends E> c){
return false;
}
public void clear() {
}
public boolean contains(E what) {
return false;
}
public boolean containsAll(Collection<?> c) {
return false;
}
public boolean equals(E what) {
return false;
}
public int hashCode() {
return 0;
}
public boolean isEmpty() {
return false;
}
public Iterator<E> iterator() {
return null;
}
public boolean remove(E what) {
return false;
}
public boolean removeAll(Collection<?> c) {
return false;
}
public boolean retainAll(Collection<?> c) {
return false;
}
public int size() {
return 0;
}
public Object[] toArray() {
return null;
}
public Object[] toArray(Object[] a){
return null;
}
}
I found this question: How to create a class that implements java.util.collections But I dont believe I am making the same mistake as that guy, or am i wrong?
Please give me some hints, i have been coding php for years but object orientation is new to me!
public boolean retainAll(Collection<?> c)instead ofpublic boolean retainAll(Collection<E> c).public boolean addAll(Collection<? extends E> c). Also hava a look at AbstractCollection - extending that instead of implementing the whole interface yourself may save some work.