r/programmingbydoing • u/FancyMonocle • Feb 11 '13
Assignment 39 - compareTo() challenge - Explanation on how it works?
The lesson gives an extremely brief description and gives you an example code from which you're able to figure out the gist of what's going on. However, I feel as if the compareTo() method isn't really explained. When I tried to run the assignment, I'd get values of positive and negative, but I wouldn't understand why I'd get specific values.
I'm guessing this is one of the assignments that's missing a lecture perhaps? I would greatly appreciate an explanation since I'm having a hard time finding good explanations from google.
View all comments
Show parent comment
3
u/holyteach Feb 11 '13
That's part of it.
The short answer is that for a.compareTo(b) you get:
The Javadocs don't actually specify anything more than that, which means technically the specific details could change in a future version of Java. That is, understanding the specifics might be interesting, but it shouldn't be helpful because any code you write relying on it could break in the future.
That said, the specifics seem to be: