Checkstyle“方法不是为扩展而设计的”错误发出错误? [英] Checkstyle "Method Not Designed For Extension" error being incorrectly issued?

查看:104
本文介绍了Checkstyle“方法不是为扩展而设计的”错误发出错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Checkstyle并且收到有关此方法的错误:

I'm using Checkstyle and am getting an error about this method:

public final String getAdmitCodeStatus() {
    return admitCodeStatus;
}

这是我得到的错误:


方法'getAdmitCodeStatus'不是为扩展而设计的 - 需要是抽象的,最终的或空的。

Method 'getAdmitCodeStatus' is not designed for extension - needs to be abstract, final, or empty.

该方法如何不符合要求?有没有什么我做错了,Checkstyle会对我这个方法咆哮?

How is that method not compliant? Is there something I'm doing wrong that Checkstyle would bark at me about this method?

推荐答案

它看起来是由 DesignForExtension 规则。根据文档

It looks to be caused by the DesignForExtension rule. According to the documentation:

检查类是否设计用于扩展。更具体地说,
强制执行一种编程风格,其中超类提供可以由子类实现的空钩子

Checks that classes are designed for extension. More specifically, it enforces a programming style where superclasses provide empty "hooks" that can be implemented by subclasses.

确切的规则是
可以被子类化的非私有非静态方法必须是

The exact rule is that nonprivate, nonstatic methods of classes that can be subclassed must either be

abstract or
final or
have an empty implementation

基本原理:这种API设计风格可以保护超类不受
的影响被子类打破。缺点是子类的灵活性限制在
,特别是它们不能阻止超类中代码
的执行,但这也意味着子类不能通过遗忘来破坏
超类的状态调用超级方法。

Rationale: This API design style protects superclasses against beeing broken by subclasses. The downside is that subclasses are limited in their flexibility, in particular they cannot prevent execution of code in the superclass, but that also means that subclasses cannot corrupt the state of the superclass by forgetting to call the super method.

来源: http://sonar.15.n6.nabble.com/design-for-extension-rule-tp3200037p3200043.html

但是因为你的方法有一个 final 修饰符,我会说你发现了一个bug并且可能想记录一个bug报告。
https://github.com/checkstyle/checkstyle/issues

But since your method has a final modifier, I'd say you found a bug and might want to log a bug report. https://github.com/checkstyle/checkstyle/issues

这篇关于Checkstyle“方法不是为扩展而设计的”错误发出错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆