java类型参数不在类型变量的范围内

1dkrff03  于 2021-07-12  发布在  Java
关注(0)|答案(1)|浏览(851)

我试图创建一个与泛型bst类具有has-a关系的类,它通过读取逗号分隔的文件来构造树。
这是我的密码:

  1. public class PatientSearchTree<ItemType extends Comparable<ItemType>>
  2. {
  3. BinarySearchTree<ItemType> patients;
  4. public PatientSearchTree(String fileName) throws IOException
  5. {
  6. BinarySearchTree<String> lines = new BinarySearchTree<String>();
  7. BufferedReader reader = null;
  8. try {
  9. reader = new BufferedReader(new FileReader(fileName));
  10. patients = new BinarySearchTree<Patient>();
  11. String line = null;
  12. while ((line = reader.readLine()) != null)
  13. {
  14. line = reader.readLine();
  15. String[] params = line.split(",");
  16. Patient tempPatient = new Patient(params[0],params[1],params[2],params[3],params[4],params[5],params[6],params[7],params[8],params[9]);
  17. patients.add(tempPatient);
  18. }
  19. } finally {
  20. reader.close();
  21. }
  22. }

我的错误是:

  1. PatientSearchTree.java:21: error: type argument
  2. PatientSearchTree.Patient is not within bounds of type-variable ItemType
  3. patients = new BinarySearchTree<Patient>();
  4. ^
  5. where ItemType is a type-variable:
  6. ItemType extends Comparable<ItemType> declared in class BinarySearchTree
2nc8po8w

2nc8po8w1#

班级 Patient 不实现接口 Comparable<Patient> .

相关问题