Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Comparator sort issue

 
Jack Bento
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there

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

Thanks in advance!

 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jack Bento
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sebastian you are a genius

I changed draft to:

 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or you could use the comparable interface

 
Jack Bento
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
good boy :-)
 
Jack Bento
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Wouter. I got the comparable going earlier
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic