posted 22 years ago
The complier doesn't consider the inter-relationsihp between the three conditions in your if statements to determine that one of the returns will always be executed. So as far as the complier is concerned, it could evalutate all three of the if conditions, not get a match, and thus fall out the bottom. You could "fix" it by adding a return 0 at the bottom.
Is there any difference between your code and
Also, don't forget that when you provide compareTo(), you usually need to override equals() and hashCode().