抽象类和接口类 取得实例

抽象类和接口不能用new()来创建实例, 但有一些库的抽象类和接口(Java 8) 提供了静态方法去创建实例,一般使用newInstance()。

例如库:

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc=builder.parse(new ByteArrayInputStream(xml.getBytes()));

 

posted on 2016-04-13 22:05  一点一滴的水  阅读(291)  评论(0编辑  收藏  举报