简体   繁体   English

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

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

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