Java类的继承

XHTMLMapper继承 XWPFDocumentVisitor:

由于endVisitTableCell是抽象方法,XHTMLMapper中必须要实现;

existErr()子类是否重写都是自由的;

java 复制代码
public abstract class XWPFDocumentVisitor<T, O extends Options, E extends IXWPFMasterPage> implements IMasterPageHandler<E> {
	public void start() throws Exception {
        ...
        ...
        existErr()
    }
 	protected abstract void endVisitTableCell(XWPFTableCell cell, T tableContainer, T tableCellContainer)
            throws Exception;
    public boolean existErr(){return false;}
}
java 复制代码
public class XHTMLMapper extends XWPFDocumentVisitor<Object, XHTMLOptions, XHTMLMasterPage> {
	@Override
    protected void endVisitTableCell(XWPFTableCell cell, Object tableContainer, Object tableCellContainer) throws Exception {
        endElement(TD_ELEMENT);
    }
	@Override
    public boolean existErr(){
        return SAXHelper.existErr(contentHandler);
    }
}
java 复制代码
XHTMLMapper mapper = new XHTMLMapper(document, contentHandler, options);
mapper.start(); // 执行父类的start(),start()内部的 existErr()会调用子类的 existErr()
相关推荐
2401_83319773几秒前
现代C++多线程编程实战
开发语言·c++·算法
m0_587958952 分钟前
C++中的适配器模式实战
开发语言·c++·算法
西门吹雪分身4 分钟前
JMM java内存模型分析
java·开发语言
不会写DN8 分钟前
Js常用数组处理
开发语言·javascript·ecmascript
回到原点的码农8 分钟前
Spring Boot 热部署
java·spring boot·后端
还是大剑师兰特10 分钟前
数组中有两个数据,将其变成字符串
开发语言·javascript·vue.js
ameyume10 分钟前
设计模式之单例模式的线程安全
java
2301_7765087210 分钟前
C++中的职责链模式实战
开发语言·c++·算法
Java烘焙师11 分钟前
AI编程实战:从零到一搭建全栈项目
java·架构·树莓派·ai实战
sqyno1sky12 分钟前
C++中的空对象模式
开发语言·c++·算法