mirror of
https://github.com/sjsdfg/effective-java-3rd-chinese.git
synced 2025-01-21 09:41:01 +08:00
Update 14. 考虑实现Comparable接口.md
wrong snippets in `compareTo` method for the `PhoneNumber` class
This commit is contained in:
parent
28e51ff3ca
commit
9e9d80eb73
@ -71,11 +71,11 @@ public final class CaseInsensitiveString
|
||||
```java
|
||||
// Multiple-field `Comparable` with primitive fields
|
||||
public int compareTo(PhoneNumber pn) {
|
||||
int result = [Short.compare(areaCode](http://Short.compare(areaCode), pn.areaCode);
|
||||
if (result == 0) {
|
||||
result = [Short.compare(prefix](http://Short.compare(prefix), pn.prefix);
|
||||
int result = Short.compare(areaCode, pn.areaCode);
|
||||
if (result == 0) {
|
||||
result = Short.compare(prefix, pn.prefix);
|
||||
if (result == 0)
|
||||
result = [Short.compare(lineNum](http://Short.compare(lineNum), pn.lineNum);
|
||||
result = Short.compare(lineNum, pn.lineNum);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user