繁体   English   中英

如何解决此绑定不匹配错误?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM