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 / First Aid / July 2006

Tip: Looking for answers? Try searching our database.

Error: uses unchecked or unsafe operations

Thread view: 
Alex - 05 Jul 2006 11:34 GMT
Hi,

I am having a problem with the above mentioned error:
Coalesce.java uses unchecked or unsafe operations.

Now I know this is to do with generics but I am not entirely sure how
to solve the problem. Here is the code that is causing it:

List<Tree> trees = new ArrayList<Tree>();
for(int i=0;i<10;i++)
        {
            trees.add(coalescents.get(i).makeTree());
            trees.get(i).calcLikelihood();
        }
Collections.sort(trees); //this line is the problem

The problem is in the "sort" method. How can I make sure the compiler
knows that I will only be passing things of type Tree to the
Colections.sort method?

Thanks,

Alex
Bart Cremers - 05 Jul 2006 11:57 GMT
Alex schreef:

> Hi,
>
[quoted text clipped - 19 lines]
>
> Alex

Just guessing here, but I think you'll need to make the Tree class
implement Comparable. An other option is to use the Collections.sort()
method which also taks a Comparator.

Regards,

Bart
Alex - 05 Jul 2006 14:49 GMT
My Trees class does implement Comparable...so I'm not sure it's that.
Also, how do I specify a Comparator to use...?

Thanks,

Alex

> Alex schreef:
>
[quoted text clipped - 29 lines]
>
> Bart
Oliver Wong - 05 Jul 2006 15:42 GMT
[post re-ordered]

>> Alex schreef:
>>
[quoted text clipped - 17 lines]
>> > knows that I will only be passing things of type Tree to the
>> > Colections.sort method?
[...]

>> Just guessing here, but I think you'll need to make the Tree class
>> implement Comparable. An other option is to use the Collections.sort()
>> method which also taks a Comparator.
[...]

> My Trees class does implement Comparable...so I'm not sure it's that.

Can you post the declaration of the Tree class? Something like:

public class Tree implements Comparable<Tree> {

> Also, how do I specify a Comparator to use...?

Use this method:
http://java.sun.com/j2se/1.5.0/docs/api/java/util/Collections.html#sort(java.uti
l.List,%20java.util.Comparator
)

   - Oliver


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.