This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes what's the error? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "what Watch "what New topic
Author

what's the error?

Nabila Mohammad
Ranch Hand

Joined: Nov 05, 2007
Posts: 661
I am getting error with this simple problem which is supposed to compile with out any problem.

I get:
incompatible types
found:TreeSet
required java.util.Set
Set s=new TreeSet();
^



The future belongs to those who believe in the beauty of their dreams.Dream BIG!
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18545
    
  40

Basically, you named your class TreeSet. So, when you instantiated a TreeSet, it will instantiate your class, and not the TreeSet in the collection classes.

And since your TreeSet doesn't implement the Set interface, you are getting the error.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Nabila Mohammad
Ranch Hand

Joined: Nov 05, 2007
Posts: 661
Thanks alot!
 
Consider Paul's rocket mass heater.
 
subject: what's the error?
 
Similar Threads
ClassCastException
Set question
code
Generic
doubt in treeset...