Skip to content

Commit 66245e7

Browse files
authored
Update 05_Enumerated_Types.md
1 parent 8e65ec9 commit 66245e7

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

ch03/05_Enumerated_Types.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,18 @@ class Season extends Enum<Season>
4343
public static <T> T max(Collection<? extends T> coll, Comparator<? super T> cmp){
4444
T candidate = coll.iterator().next();
4545
for (T elt : coll) {
46-
if (cmp.compare(candidate, elt) < 0) { candidate = elt; }
47-
}
46+
if (cmp.compare(candidate, elt) < 0) { candidate = elt; }
47+
}
4848
return candidate;
4949
}
5050
public static <T extends Comparable<? super T>> T max(Collection<? extends T> coll){
51-
return max(coll, Comparators.<T>naturalOrder());
52-
}
53-
public static <T> T min(Collection<? extends T> coll, Comparator<? super T> cmp){
54-
return max(coll, reverseOrder(cmp));
51+
return max(coll, Comparators.<T>naturalOrder());
5552
}
56-
public static <T extends Comparable<? super T>> T min(Collection<? extends T> coll){
57-
return max(coll, Comparators.<T>reverseOrder());
53+
public static <T> T min(Collection<? extends T> coll, Comparator<? super T> cmp){
54+
return max(coll, reverseOrder(cmp));
55+
}
56+
public static <T extends Comparable<? super T>> T min(Collection<? extends T> coll){
57+
return max(coll, Comparators.<T>reverseOrder());
5858
}
5959
public static <T extends Comparable<? super T>> Comparator<T> naturalOrder(){
6060
return new Comparator<T>() {
@@ -87,7 +87,7 @@ class Season extends Enum<Season>
8787
public final int ordinal() { return ordinal; }
8888
public String toString() { return name; }
8989
public final int compareTo(E o) {
90-
return ordinal - o.ordinal;
90+
return ordinal - o.ordinal;
9191
}
9292
}
9393
```
@@ -170,5 +170,5 @@ class Season extends Enum<Season>
170170
阵列至关重要。请注意,调用 `clone` 方法时不需要强制转换,因为克隆数组现在可以利用协变返回类型(请参见第 `3.8` 节)。 `valueOf` 方法接受一个字符串并
171171
返回相应的常量,通过搜索内部数组找到。如果字符串没有命名枚举值,它将返回 `IllegalArgumentException`。
172172

173-
《《《 [下一节](06_Multiple Bounds.md) <br/>
173+
《《《 [下一节](06_Multiple_Bounds.md) <br/>
174174
《《《 [返回首页](../README.md)

0 commit comments

Comments
 (0)