We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 8c3733a commit 14824f1Copy full SHA for 14824f1
ch08/04_Maintain_Binary_Compatibility.md
@@ -24,17 +24,15 @@ public static Object max(Collection coll)
24
25
```java
26
// 通用版本 - 打破二进制兼容性
27
-public static <T extends Comparable<? super T>>
28
-T max(Collection<? extends T> coll)
+public static <T extends Comparable<? super T>> T max(Collection<? extends T> coll)
29
```
30
31
但是这个签名有错误的擦除 - 它的返回类型是 `Comparable` 而不是 `Object`。 为了获得正确的签名,我们需要使用多重边界来摆弄类型参数的边界(参见第
32
`3.6` 节)。 这是更正后的版本:
33
34
35
// 通用版本 - 保持二进制兼容性
36
-public static <T extends Object & Comparable<? super T>>
37
+public static <T extends Object & Comparable<? super T>> T max(Collection<? extends T> coll)
38
39
40
当有多个边界时,最左边界被用于擦除。 所以 `T` 的删除现在是 `Object`,给出了我们需要的结果类型。
0 commit comments