简体   繁体   中英

How do I fix this bound mismatch error?

by <Item> it's saying : -

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.

Your Item class is implementing the raw form of the Comparable interface. You should have it implement the generic form, by declaring a type parameter on Item itself. Then, ExpandableArrayList can implement the generic form of 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 . It should contain Item s; this fails the "is-a" test. ExpandableArrayList shouldn't extend Item at all.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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