可能重複:
What are the reasons why Map.get(Object key) is not (fully) generic爲什麼幾個java.util.List方法不使用type參數?
這是類似的問題here,對java.util.Map。這個問題留給了這個問題。
的List
接口包含幾個方法仍然接受一個對象作爲參數,泛型在Java 5中引入如後:
boolean contains(Object o)
int lastIndexOf(Object o)
boolean remove(Object o)
我期待這些方法使用的類型參數。事情是這樣的:
boolean contains(E e) // Where the interface is defined as List<E>
雖然,它必須是<? extends E>
,但我不知道語法是的。
是否有設計原因,爲什麼這些方法需要一個對象,或者它是爲了向後的字節碼兼容性,還是另一個原因?
這是一個欺騙 - 只是試圖找到正確的問題... –
但凱文乙在這裏有答案之前,我發現我的參考:) http://smallwig.blogspot.com/2007/12/why-does-setcontains-take-object -not-e.html –
明白了:http://stackoverflow.com/questions/857420/what-are-the-reasons-why-map-getobject-key-is-not-fully-generic(談論地圖而不是比列表,但它是相同的交易)。 –