-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Chapter 16 confirmation #86
Comments
Hi Vishnu! Actually, it can be both, Integer.valueOf(x).compareTo(Integer.valueOf(y)) Since that part of the chapter is about the Comparable interface, I used // instead of using Integer.compareTo() To: // instead of using Integer.valueOf(this.id).compareTo(other.id) or Integer.compare(this.id, other.id) What do you think? Thanks! |
Hi,
I think it should be changed to what you have mentioned in the last line.
It's less ambiguous that way :)
Thanks,
Vishnu
…On Wed, 30 Oct 2019, 6:51 am Esteban Herrera, ***@***.***> wrote:
Hi Vishnu!
Actually, it can be both, Integer.compareTo(Integer i) or Integer.compare(int
a, int b). According to the documentation
<https://docs.oracle.com/javase/8/docs/api/java/lang/Integer.html#compare-int-int->,
compare(int a, int b) is the same as:
Integer.valueOf(x).compareTo(Integer.valueOf(y))
Since that part of the chapter is about the Comparable interface, I used
comparedTo. Do you think it would be better to change:
// instead of using Integer.compareTo()
To:
// instead of using Integer.valueOf(this.id).compareTo(other.id) or Integer.compare(this.id, other.id)
What do you think?
Thanks!
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#86?email_source=notifications&email_token=ADFQTOEVZQFSNSGV7FOZOMTQRDOTJA5CNFSM4JGPPWP2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECSTMWY#issuecomment-547698267>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADFQTOBFMPTIGK5WQ5FADVTQRDOTJANCNFSM4JGPPWPQ>
.
|
Changed, thanks to you! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Esteban,
The book has been great so far.
One quick confirmation I wanted regarding this comment in the Comparable interface code:
// If the objects are equal, compare by id
if(result == 0) {
// Let's do the comparison "manually"
// instead of using Integer.compareTo()
if(this.id > other.id) result = 1;
else if( this.id < other.id) result = -1;
// else result = 0;
}
The line in question is :
// Let's do the comparison "manually"
// instead of using Integer.compareTo()
Could you confirm that you actually meant Integer.compare(int a, int b) as compareTo is misleading [ the signature might be different ]
Please correct me if I am wrong here.
Thanks,
Vishnu
The text was updated successfully, but these errors were encountered: