我试图创建一个与泛型bst类具有has-a关系的类,它通过读取逗号分隔的文件来构造树。
这是我的密码:
public class PatientSearchTree<ItemType extends Comparable<ItemType>>
{
BinarySearchTree<ItemType> patients;
public PatientSearchTree(String fileName) throws IOException
{
BinarySearchTree<String> lines = new BinarySearchTree<String>();
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(fileName));
patients = new BinarySearchTree<Patient>();
String line = null;
while ((line = reader.readLine()) != null)
{
line = reader.readLine();
String[] params = line.split(",");
Patient tempPatient = new Patient(params[0],params[1],params[2],params[3],params[4],params[5],params[6],params[7],params[8],params[9]);
patients.add(tempPatient);
}
} finally {
reader.close();
}
}
我的错误是:
PatientSearchTree.java:21: error: type argument
PatientSearchTree.Patient is not within bounds of type-variable ItemType
patients = new BinarySearchTree<Patient>();
^
where ItemType is a type-variable:
ItemType extends Comparable<ItemType> declared in class BinarySearchTree
1条答案
按热度按时间2nc8po8w1#
班级
Patient
不实现接口Comparable<Patient>
.