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()
相关推荐
记忆多2 分钟前
c++名字空间 函数模版 左右值
开发语言·c++·算法
lhbian10 分钟前
【Spring Cloud Alibaba】基于Spring Boot 3.x 搭建教程
java·spring boot·后端
2401_889884661 小时前
高性能计算通信库
开发语言·c++·算法
代码雕刻家1 小时前
3.6.Maven-依赖管理-依赖范围
java·maven
范什么特西2 小时前
狂神报错页面设置
java·tomcat
架构师沉默2 小时前
AI 真的会取代程序员吗?
java·后端·架构
Memory_荒年2 小时前
ReentrantLock 线程安全揭秘:从“锁”到“重入”的魔法
java·后端·源码
L0CK2 小时前
秒杀异步下单业务逻辑梳理
java
zuoerjinshu2 小时前
【spring专题】编译spring5.3源码
java·后端·spring
JavaGuide2 小时前
鹅厂面试:SELECT * 一定导致索引失效?常见索引失效场景有哪些?
java·数据库·后端·mysql·大厂面试