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()
相关推荐
从琳开始98912 小时前
网络原理入门(二)------OSI七层模型?TCP/IP五层(四层)模型原来是这样的
java·网络·tcp/ip·java-ee·php
文丑颜不良啊12 小时前
LeetCode1861~1880题目解析
java·leetcode
Flynn Liang12 小时前
AgentScope Java 深度解析:ReActAgent、HarnessAgent 与多智能体编排——JVM 上的自治 Agent 底座
java·大模型·架构设计·ai agent·spring ai·langchain4j·agentscope
Flynn Liang13 小时前
上线后怎么排查 AI 调用?Spring AI Observability:token/延迟/成本埋点与全链路追踪
java·人工智能·spring·监控·可观测性·observability·springai
文丑颜不良啊13 小时前
LeetCode1921~1940题目解析
java·leetcode
Tt有了t13 小时前
设计模式速查
java·python·设计模式
Thomas.Sir13 小时前
第15课:SpringBoot连接池详解:HikariCP配置、调优、监控,4.x连接池新特性
java·spring boot
VimorphTech14 小时前
每批开 4 个线程,为什么限制不住 TTS 的总并发?
java·spring boot·spring
Pniubi14 小时前
Java为什么要分堆和栈
java·开发语言
杨凯凡14 小时前
Spring Boot 缓存一致性怎么保证?@Cacheable、@CacheEvict 与事务提交时机实战
java·spring boot·spring cache·后端开发·缓存一致性