Collections.min / max方法的签名 [英] Signature of Collections.min/max method
本文介绍了Collections.min / max方法的签名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public static< T extends Object&可比< ;? super T>> T min(Collection <?extends T> c)
其签名以其高级用途而闻名泛型的
非常多,以至于它在Java中以简单的书
和官方的 Sun Generics Tutorial 。
然而,我找不到令人信服的答案来回答以下问题: p>
为什么类型 Collection的形式参数<?延伸T>
,而不是
比集合< T>
?什么是额外的好处?
解决方案
?
的好处之一是它禁止将项目添加到集合
In Java, the Collections class contains the following method:
public static <T extends Object & Comparable<? super T>> T min(Collection<? extends T> c)
Its signature is well-known for its advanced use of generics, so much that it is mentioned in the Java in a Nutshell book and in the official Sun Generics Tutorial.
However, I could not find a convincing answer to the following question:
Why is the formal parameter of type Collection<? extends T>
, rather
than Collection<T>
? What's the added benefit?
解决方案
One benefit of the ?
is that it prohibits additions of items to the Collection
这篇关于Collections.min / max方法的签名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文