[英]How do I fix this bound mismatch error?
by <Item>
it's saying : - 通过<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> ();
These are my headers: 这些是我的标题:
public interface ListInterface <T extends Comparable <? super T>>
public class ExpandableArrayList<T extends Comparable<?super T>> extends Item {
public class Item implements Comparable
I can't figure out what I need to change exactly. 我无法弄清楚我到底需要改变什么。 Every time I change something in one header other errors pop up. 每次我在一个标头中更改某些内容时,都会弹出其他错误。 I use the compareTo(Object obj) type. 我使用compareTo(Object obj)类型。
Your Item
class is implementing the raw form of the Comparable
interface. 您的Item
类正在实现Comparable
接口的原始形式。 You should have it implement the generic form, by declaring a type parameter on Item
itself. 您应该通过在Item
本身上声明类型参数来实现通用形式。 Then, ExpandableArrayList
can implement the generic form of Item
. 然后, ExpandableArrayList
可以实现Item
的通用形式。
public class Item<T extends Comparable <? super T>> implements Comparable<T>
and 和
public ExpandableArrayList<T extends Comparable<?super T>> extends Item<T>
This will resolve compilation problems due to the headers. 这将解决由于标题引起的编译问题。
But it's unclear why an ExpandableArrayList
should subclass Item
. 但是尚不清楚为什么ExpandableArrayList
应该子类Item
。 It should contain Item
s; 它应包含Item
; this fails the "is-a" test. 这没有通过“是”测试。 ExpandableArrayList
shouldn't extend Item
at all. ExpandableArrayList
根本不应扩展Item
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.