S
Stofdeel
Hello,
trying to implement the 'java.util.Collection' interface. Get the following
error.
<ERROR>
MyCollection is not abstract and does not override abstract method
retainAll(java.util.Collection) in java.util.Collection
</ERROR>
<REASON>
"This error is reported when a class implements an interface but does not
supply all the necessary methods or misspells a method name, or has the the
wrong number or types of parameters in one of the interface methods."
</REASON>
But I do implement 'retainAll'...I am missing something here, but I can't
see what. It is not the keyword 'synchronized'. It's not giving the
parameter another name. See code snippet below. I assume the error has
nothing to do with the rest of my code. Any help is appriciated,
thanks.
<MY CODE>
public class MyCollection<E> implements Collection
{
...
public synchronized boolean retainAll(Collection<?> objCollection)
{
boolean blnModified = false;
Iterator<E> objIterator = iterator();
while (objIterator.hasNext())
{
if (!objCollection.contains(objIterator.next()))
{
objIterator.remove();
blnModified = true;
}
}
return blnModified;
}
...
}
</MY CODE>
<JAVA CODE>
public interface Collection<E> extends Iterable<E>
{
// Basic operations
int size();
boolean isEmpty();
boolean contains(Object element);
boolean add(E element); // optional
boolean remove(Object element); // optional
Iterator iterator();
// Bulk operations
boolean containsAll(Collection<?> c);
boolean addAll(Collection<? extends E> c); // optional
boolean removeAll(Collection<?> c); // optional
boolean retainAll(Collection<?> c); // optional
void clear(); // optional
// Array operations
Object[] toArray();
<T> T[] toArray(T[] a);
}
</JAVA CODE>
trying to implement the 'java.util.Collection' interface. Get the following
error.
<ERROR>
MyCollection is not abstract and does not override abstract method
retainAll(java.util.Collection) in java.util.Collection
</ERROR>
<REASON>
"This error is reported when a class implements an interface but does not
supply all the necessary methods or misspells a method name, or has the the
wrong number or types of parameters in one of the interface methods."
</REASON>
But I do implement 'retainAll'...I am missing something here, but I can't
see what. It is not the keyword 'synchronized'. It's not giving the
parameter another name. See code snippet below. I assume the error has
nothing to do with the rest of my code. Any help is appriciated,
thanks.
<MY CODE>
public class MyCollection<E> implements Collection
{
...
public synchronized boolean retainAll(Collection<?> objCollection)
{
boolean blnModified = false;
Iterator<E> objIterator = iterator();
while (objIterator.hasNext())
{
if (!objCollection.contains(objIterator.next()))
{
objIterator.remove();
blnModified = true;
}
}
return blnModified;
}
...
}
</MY CODE>
<JAVA CODE>
public interface Collection<E> extends Iterable<E>
{
// Basic operations
int size();
boolean isEmpty();
boolean contains(Object element);
boolean add(E element); // optional
boolean remove(Object element); // optional
Iterator iterator();
// Bulk operations
boolean containsAll(Collection<?> c);
boolean addAll(Collection<? extends E> c); // optional
boolean removeAll(Collection<?> c); // optional
boolean retainAll(Collection<?> c); // optional
void clear(); // optional
// Array operations
Object[] toArray();
<T> T[] toArray(T[] a);
}
</JAVA CODE>