[英]How do I fix this bound mismatch error?
通過<Item>
表示:-
Bound mismatch: The type Item is not a valid substitute for the bounded parameter <T extends
Comparable<? super T>> of the type ExpandableArrayList<T>
ExpandableArrayList<Item> items = new ExpandableArrayList<Item> ();
這些是我的標題:
public interface ListInterface <T extends Comparable <? super T>>
public class ExpandableArrayList<T extends Comparable<?super T>> extends Item {
public class Item implements Comparable
我無法弄清楚我到底需要改變什么。 每次我在一個標頭中更改某些內容時,都會彈出其他錯誤。 我使用compareTo(Object obj)類型。
您的Item
類正在實現Comparable
接口的原始形式。 您應該通過在Item
本身上聲明類型參數來實現通用形式。 然后, ExpandableArrayList
可以實現Item
的通用形式。
public class Item<T extends Comparable <? super T>> implements Comparable<T>
和
public ExpandableArrayList<T extends Comparable<?super T>> extends Item<T>
這將解決由於標題引起的編譯問題。
但是尚不清楚為什么ExpandableArrayList
應該子類Item
。 它應包含Item
; 這沒有通過“是”測試。 ExpandableArrayList
根本不應擴展Item
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.