在java中,接口只包含方法类型、名称和参数。实际的实现是在实现它的类中完成的。鉴于此,如何创建接口的实例并像使用类对象一样使用它?有很多这样的接口,例如org.w3c.dom.Node。
这是我正在使用的代码:
DocumentBuilderFactory fty = DocumentBuilderFactory.newInstance();
fty.setNamespaceAware(true);
DocumentBuilder builder = fty.newDocumentBuilder();
ByteArrayInputStream bais = new ByteArrayInputStream(result.getBytes());
Document xmldoc = builder.parse(bais);
NodeList rm1 = xmldoc.getElementsByTagName("Subject");
Node rm3 = rm1.item(0);