I'm trying to write a method to execute a JDOM2 XPath. I would like to be able to pass in any type of filter (e.g. Filter<Content>
or Filter<Element>
. I'm passing in an Element. Element is an interface that extends the Content filter. The compiler warns
"The method executeXPath(Document, String, String, Filter<Content>
) in the type XMLUtilities is not applicable for the arguments (Document, String, String, Filter<Element>)
"
Is there a way to do this without having to create a separate method for each of the Content types?
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) {...}
You could make your method generic:
If you pass it a
Filter<Content>
it returns aList<Content>
, if you pass it aFilter<Element>
it'll return aList<Element>
, etc.