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()
相关推荐
枫叶丹412 小时前
语音 AI 怎样边听边答:实时对话系统的工作原理
开发语言·人工智能·chatgpt·开源·php·agent·codex
阿狗童鞋12 小时前
高并发系统设计实战指南
java·spring boot·spring cloud
xie0510_12 小时前
Any类简要实现
开发语言·c++·算法
Sam_Deep_Thinking12 小时前
CountDownLatch实现原理
java·后端·面试·程序员
小狼Solar12 小时前
SAP MDG 功能范围说明(基于S/4HANA 2025)
java·开发语言
kimnoic12 小时前
Python常用标准库模块及查询使用方法
开发语言·python
范中勤12 小时前
Python 与 Java:模块、包、对象、反射核心差异总结
java·python·面试·反射·元类
ab12376812 小时前
Spring Integration 完整笔记 + 和 spring-integration-mqtt、Paho、EMQX 的关系
java·笔记·spring
小蜗牛狂飙记12 小时前
java环境一键配置和切换的ui工具
java
逆光的July12 小时前
可靠消息投递与消费的工程设计:Outbox、幂等、死信兜底
java