This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
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


Win a copy of Head First Android this week in the Android forum!
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
 
Don't get me started about those stupid light bulbs.
 
subject: Comparator sort issue
 
It's not a secret anymore!