1
我试图编写一个方法来执行JDOM2 XPath。我想能够在任何类型的过滤器来传递(例如Filter<Content>
或Filter<Element>
。我传递中的元素。元素是一个扩展内容过滤的接口。编译器警告无法从XPathExpression <Object>转换为XPathExpression <Content>
“的方法executeXPath(Document, String, String, Filter<Content>
)在XMLUtilities类型不适用于参数(Document, String, String, Filter<Element>)
“
有没有办法做到这一点,而无需为每种内容类型创建单独的方法?
Filter<Element> filter = new org.jdom2.filter.ElementFilter();
List<Element> xPathSearchedNodes = XMLUtilities.executeXPath(doc, "/x:root","http://www.example.com",filter);
....
static public List<Content> executeXPath(Document document, String xpathStr, String namespace, Filter<Content> filter) {...}
我不得不使用“<?extends Content>”为c ompiler不要抱怨,然后在客户端投这个名单。 –
user994165