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()
相关推荐
猫头虎1 分钟前
什么是ZCode for GLM-5.2?
开发语言·人工智能·python·科技·算法·ai编程·ai写作
Ivanqhz26 分钟前
Rust Lazy浅析
java·javascript·rust
bksczm1 小时前
Linux之日志和线程池、内存池
java·开发语言
笨蛋不要掉眼泪1 小时前
Java虚拟机:对象复活、引用强度与Stop-The-World
java·开发语言·jvm
布朗克1681 小时前
Go 入门到精通-33-unsafe 与 CGO
开发语言·后端·golang·unsafe·cgo
个 人 练 习 生1 小时前
strcmp与strstr函数的模拟实现
c语言·开发语言·经验分享·学习·程序人生
凤山老林1 小时前
SpringBoot实战:构建优雅的全局异常处理机制
java·springboot·异常处理
157092511342 小时前
【无标题】
开发语言·python·算法
小Ti客栈2 小时前
Spring Boot 整合 Swagger2 和 Knife4j实现接口文档与可视化调试
java·spring boot·后端
梅头脑2 小时前
ThreadLocalMap里几十万个死Entry——排查了半天OOM,根因就一行finally没写
java