Java 无法从XPathExpression强制转换<;对象>;到xpatexpression<;内容>;

Java 无法从XPathExpression强制转换<;对象>;到xpatexpression<;内容>;,java,jdom,Java,Jdom,我正在尝试编写一个方法来执行JDOM2 XPath。我希望能够传入任何类型的筛选器(例如,filter或filter。我传入一个元素。元素是扩展内容筛选器的接口。编译器发出警告 XMLUtilities类型中的方法executeXPath(Document,String,String,Filter)不适用于参数(Document,String,String,Filter) 有没有一种方法可以做到这一点,而不必为每种内容类型创建单独的方法 Filter<Element> filter

我正在尝试编写一个方法来执行JDOM2 XPath。我希望能够传入任何类型的筛选器(例如,
filter
filter
。我传入一个元素。元素是扩展内容筛选器的接口。编译器发出警告

XMLUtilities类型中的方法
executeXPath(Document,String,String,Filter
)不适用于参数
(Document,String,String,Filter)

有没有一种方法可以做到这一点,而不必为每种内容类型创建单独的方法

Filter<Element> filter = new org.jdom2.filter.ElementFilter();
List<Element> xPathSearchedNodes = XMLUtilities.executeXPath(doc, "/x:root","http://www.example.com",filter);
Filter-Filter=new org.jdom2.Filter.ElementFilter();
列出xPathSearchedNodes=XMLUtilities.executeExpath(doc,“/x:root,”http://www.example.com“,过滤器);

static public List executeXPath(文档文档、字符串xpathStr、字符串命名空间、过滤器){…}

您可以将您的方法设置为通用:

static public <T extends Content> List<T> executeXPath(Document document, String xpathStr, String namespace, Filter<T> filter) {...}
static public List executeXPath(文档文档、字符串xpathStr、字符串命名空间、过滤器){…}
如果你给它传递一个
过滤器
它会返回一个
列表
,如果你给它传递一个
过滤器
它会返回一个
列表
,等等。

我不得不使用“
static public <T extends Content> List<T> executeXPath(Document document, String xpathStr, String namespace, Filter<T> filter) {...}