Skip to content

Commit 14824f1

Browse files
authored
Update 04_Maintain_Binary_Compatibility.md
1 parent 8c3733a commit 14824f1

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

ch08/04_Maintain_Binary_Compatibility.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,15 @@ public static Object max(Collection coll)
2424

2525
```java
2626
// 通用版本 - 打破二进制兼容性
27-
public static <T extends Comparable<? super T>>
28-
T max(Collection<? extends T> coll)
27+
public static <T extends Comparable<? super T>> T max(Collection<? extends T> coll)
2928
```
3029

3130
但是这个签名有错误的擦除 - 它的返回类型是 `Comparable` 而不是 `Object`。 为了获得正确的签名,我们需要使用多重边界来摆弄类型参数的边界(参见第
3231
`3.6` 节)。 这是更正后的版本:
3332

3433
```java
3534
// 通用版本 - 保持二进制兼容性
36-
public static <T extends Object & Comparable<? super T>>
37-
T max(Collection<? extends T> coll)
35+
public static <T extends Object & Comparable<? super T>> T max(Collection<? extends T> coll)
3836
```
3937

4038
当有多个边界时,最左边界被用于擦除。 所以 `T` 的删除现在是 `Object`,给出了我们需要的结果类型。

0 commit comments

Comments
 (0)