Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
请参见下面的示例,与有界类型参数相比有什么f(U u)好处g(I obj)?
f(U u)
g(I obj)
interface I {} class A { public static <U extends I> void f(U u){ } public static void g(I obj) { } }
对于这种特殊情况,没有任何内容。您可以在U(知道U extends I)上执行与在I.
U
U extends I
I
更多情况下,您会看到它产生实际影响的案例:
public static <U extends I> void f(Collection<U> collection)
或者,更一般地说,有界类型参数被用作另一个泛型类型的参数。