File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Comparator sort issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Comparator sort issue" Watch "Comparator sort issue" New topic
Author

Comparator sort issue

Jack Bento
Ranch Hand

Joined: Jun 14, 2009
Posts: 34
Hi there

Please can you let me know where I went wrong with my sort method?

Thanks in advance!

Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
It should throw a big fat exception ...

Your comparator expects two Strings but what it gets is two Jolies.
What exactly is it that you want to compare ??

What you need to do is parameterize Draft with Jolie2 and then compare the necessary values.


JDBCSupport - An easy to use, light-weight JDBC framework -
Jack Bento
Ranch Hand

Joined: Jun 14, 2009
Posts: 34
Sebastian you are a genius

I changed draft to:

Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
sure

why are you using a getter for a but direct access for b ??? and why are your instance variables not private ?
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Or you could use the comparable interface



"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Jack Bento
Ranch Hand

Joined: Jun 14, 2009
Posts: 34
Sebastian Janisch wrote:sure

why are you using a getter for a but direct access for b ??? and why are your instance variables not private ?

I was just trying to get the comparator working. You're right, mustn't get into bad habits.
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
good boy :-)
Jack Bento
Ranch Hand

Joined: Jun 14, 2009
Posts: 34
Thanks Wouter. I got the comparable going earlier
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Comparator sort issue