谁能解释一下为什么这段代码不能编译:
import java.io.FileInputStream;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.events.XMLEvent;
public class Test {
public static void main(String[] args) throws Exception {
XMLEventReader xr = XMLInputFactory.newInstance().createXMLEventReader(new FileInputStream("test.xml"));
XMLEvent e = xr.next();
}
}
输出
Test.java:10: error: incompatible types
XMLEvent e = xr.next();
^
required: XMLEvent
found: Object
1 error
根据 API XMLEventReader.next() 返回 XMLEvent。
注意:我使用 javac 1.7.0_03