Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2006

Tip: Looking for answers? Try searching our database.

Interface.

Thread view: 
Stofdeel - 11 Jun 2006 10:22 GMT
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>
Stofdeel - 11 Jun 2006 13:55 GMT
Nevermind, found the error....forgot "<E>" after "implements
Collection"...strange error that produces tho.

Thanks

> Hello,
>
[quoted text clipped - 66 lines]
> }
> </JAVA CODE>
Mike Schilling - 12 Jun 2006 00:54 GMT
> Nevermind, found the error....forgot "<E>" after "implements
> Collection"...strange error that produces tho.

The error is correct: a non-genericized collection (say, one where you
haven't changed the code since 1.4) needs to implement
retainAll(Collection), not retainAll(Collection<?>), and yours did not.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.