如何在具有抽象类型的 ListView 上调用方法

How to call a method on a ListView which has an abstract type

我在 getNodes() 方法中遇到错误。 ***

    The method getfilter(ListView<CellObject>) in the type NodeUtil is not 
applicable for the arguments (ListView<Index>)

但是由于 Index 实现了 CellObject,并且 Employee 扩展了 Index,它应该可以工作吗?

public abstract class Index implements CellObject {

}

..

@FXML private ListView <Index> listView;

public List<Node> getNodes() {
     List<Node> nodes = new ArrayList<>();
     ***nodes.add(NodeUtil.getfilter(listView));***
     return nodes;
 }


public class Employee extends Index {
    @Override
    public String getInfo() {
        return name + address;
    }

}


public abstract class NodeUtil {
    public static List <Node> getfilter(ListView <CellObject> lv) {
         ...
         lv.getItems().stream()
            .filter(c -> c.getInfo().contains("xxx"))
             ...
    }

}

在泛型中,您必须指定是要特定类型还是 extends 特定类型的类型,请使用:

    public static List <Node> getfilter(ListView < ?  extends CellObject > lv) {