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()
相关推荐
sco52828 分钟前
SpringBoot 自动装配原理 & 自定义一个 starter
java·spring boot·后端
曼岛_16 分钟前
[Java实战]Spring Boot 快速配置 HTTPS 并实现 HTTP 自动跳转(八)
java·spring boot·http
_Itachi__27 分钟前
LeetCode 热题 100 543. 二叉树的直径
java·算法·leetcode
风吹落叶325739 分钟前
线程的一些事(2)
java·java-ee
宸汐Fish_Heart42 分钟前
Python打卡训练营Day22
开发语言·python
菜狗想要变强43 分钟前
C++ STL入门:vecto容器
开发语言·c++
是代码侠呀1 小时前
飞蛾扑火算法matlab实现
开发语言·算法·matlab·github·github star·github 加星
Uncomfortableskiy1 小时前
Rust 官方文档:人话版翻译指南
开发语言·rust
名字不要太长 像我这样就好1 小时前
【iOS】源码阅读(二)——NSObject的alloc源码
开发语言·macos·ios·objective-c
追逐梦想之路_随笔1 小时前
gvm安装go报错ERROR: Failed to use installed version
开发语言·golang