javaxmldom4j

how can I eliminate unchecked assignment warning in using dom4j Iterator


warning code:

for (Iterator<Element> iterator = element.elementIterator(); iterator.hasNext(); ) {
   // some code
}

warning information:

Unchecked assignment: 'java.util.Iterator' to 'java.util.Iterator<org.dom4j.Element>'

Solution

  • The clean way would be to upgrade to the dom4j 2.0 library, which defines elementIterator() to return a parameterized type: https://dom4j.github.io/javadoc/2.0.0/org/dom4j/Element.html

    With your code as-is, you could use a @supressWarnings() annotation to silence the complaint...