[英]JAVA : Bound mismatch: is not a valid substitute for the bounded parameter <E extends Comparable<E>>
i have the class BinaryTree: 我有BinaryTree类:
public class BinaryTree<E extends Comparable<E>> extends AbstractTree<E> {
protected TreeNode<E> root;
protected int size = 0;
private final Comparator<? super E> comparator;
/** Create a default binary tree */
public BinaryTree() {
comparator = null;
}
/** Create a binary tree from an array of objects */
public BinaryTree(E[] objects) {
for (int i = 0; i < objects.length; i++)
insert(objects[i]);
}
public BinaryTree(E[] objects, Comparator<E> c) {
for (int i = 0; i < objects.length; i++)
insert(objects[i]);
}
//some getters, setters, insert, search and etc...
}
Also i have MyQueue Class: 我也有MyQueue类:
public class MyQueue<E> {
private LinkedList<E> list = new LinkedList<E>();
public void enqueue(E e) {
list.addLast(e);
}
public E dequeue() {
return list.removeFirst();
}
public int getSize() {
return list.size();
}
public String toString() {
return "Queue: " + list.toString();
}
}
And finally i have the CreditCardTransaction class: 最后我有了CreditCardTransaction类:
public class CreditCardTransaction {
private int cardNumber;
private String customerName;
private int amount;
public CreditCardTransaction(int cardNumber, String customerName, int amount) {
this.cardNumber = cardNumber;
this.customerName = customerName;
this.amount = amount;
}
public int getCardNumber() {
return cardNumber;
}
public void setCardNumber(int cardNumber) {
this.cardNumber = cardNumber;
}
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
public int getAmount() {
return amount;
}
public void setAmount(int amount) {
this.amount = amount;
}
}
In the main i wrote: 在主要我写道:
BinaryTree<MyQueue<CreditCardTransaction>> e = new BinaryTree<MyQueue<CreditCardTransaction>>();
i get the error: 我收到错误:
Bound mismatch: The type MyQueue<CreditCardTransaction> is not a valid substitute for the bounded parameter <E extends Comparable<E>> of the type BinaryTree<E>
I try all kind of mix with the types and any time the eclipse gave me this error, any help please? 我尝试各种类型的混合,每当日食给我这个错误,任何帮助,请?
EDIT 编辑
I added to MyQueue 我加入了MyQueue
public class MyQueue<E> implements Comparable<E>{
@Override
public int compareTo(E o) {
// TODO Auto-generated method stub
return 0;
}
}
and in the main it still gave me the error: 而在主要它仍然给了我错误:
Bound mismatch: The type MyQueue<CreditCardTransaction> is not a valid
substitute for the bounded parameter <E extends Comparable<E>> of the
type BinaryTree<E>
MyQueue
does not implement Comparable
, so it can't substitute the type parameter of BinaryTree
. MyQueue
没有实现Comparable
,所以它不能代替的类型参数BinaryTree
。
You can either remove the extends Comparable<E>
bound from BinaryTree
if you don't need it, or change MyQueue
to implement Comparable<MyQueue<E>>
. 您可以删除
extends Comparable<E>
从势必BinaryTree
,如果你不需要它,或者改变MyQueue
实现Comparable<MyQueue<E>>
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.