Skip to content
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

Open
VishGov opened this issue Oct 29, 2019 · 3 comments
Open

Chapter 16 confirmation #86

VishGov opened this issue Oct 29, 2019 · 3 comments

Comments

@VishGov
Copy link

VishGov commented Oct 29, 2019

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

@eh3rrera
Copy link
Owner

Hi Vishnu!

Actually, it can be both, Integer.compareTo(Integer i) or Integer.compare(int a, int b). According to the documentation, 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!

@VishGov
Copy link
Author

VishGov commented Oct 30, 2019 via email

eh3rrera added a commit that referenced this issue Nov 3, 2019
@eh3rrera
Copy link
Owner

eh3rrera commented Nov 3, 2019

Changed, thanks to you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants