• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

CompareTo method

 
Beckie Wirefly
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

This is my first post, so I hope I am doing this correctly. I am studying Programming at University (College) and am a little stuck on the CompareTo method in the Comparable interface.


What I need to do is:
If the price is equal (return 0), then compare the area's.

I hope this is clear enough, here is my code:




I believe I am doing the correct thing, but not too sure. I think the problem may lay in comparing two objects???

Thank you for your insight.

Beckie
 
Henry Wong
author
Marshal
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Line 61 and after, of the compareTo() method, should be unreachable -- as it is not possible to get pass the if-then statement without returning from the method.

Henry
 
Beckie Wirefly
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
Line 61 and after, of the compareTo() method, should be unreachable -- as it is not possible to get pass the if-then statement without returning from the method.

Henry


Of course, thank you for correcting that for me!!

Beckie
 
Rob Spoor
Sheriff
Pie
Posts: 20396
47
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

That only returns true if o is an Integer object, but at that point (should it be reached by removing a previous return statement) you already know that o is a House object - or the cast on line 54 would already have failed.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic