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 分钟前
Springboot基础教程(8)--Shiro
java·spring boot·后端
dzl843945 分钟前
springboot脚手架备忘
java
feathered-feathered8 分钟前
网络套接字——Socket网络编程(TCP编程详解)
java·网络·后端·网络协议·tcp/ip
路边草随风2 小时前
java实现发布spark yarn作业
java·spark·yarn
为爱停留2 小时前
Spring AI实现MCP(Model Context Protocol)详解与实践
java·人工智能·spring
汝生淮南吾在北5 小时前
SpringBoot+Vue饭店点餐管理系统
java·vue.js·spring boot·毕业设计·毕设
fish_xk5 小时前
c++中的引用和数组
开发语言·c++
酒尘&8 小时前
JS数组不止Array!索引集合类全面解析
开发语言·前端·javascript·学习·js
冬夜戏雪8 小时前
【java学习日记】【2025.12.7】【7/60】
java·开发语言·学习
xwill*8 小时前
分词器(Tokenizer)-sentencepiece(把训练语料中的字符自动组合成一个最优的子词(subword)集合。)
开发语言·pytorch·python