java - 如何启用 checkstyle 的 MissingOverride 检查?
问题描述
我有一个
public interface Interface0 {
void method0();
}
和一个
public class Implementation0 implements Interface0 {
public void method0() {
throw new UnsupportedOperationException("Not supported yet.");
}
}
我maven-checkstyle-plugin
通过声明使用
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>checkstyle</id>
<phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<configuration>
<configLocation>${basedir}/check_style.xml</configLocation>
</configuration>
</plugin>
最后我正在MissingOverride
激活check_style.xml
:
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.2//EN"
"http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
<module name="Checker">
<module name="TreeWalker">
<module name="MissingOverride"/>
</module>
</module>
这是我在许多项目中的经验摘录,所有检查都可以正常工作,除了MissingOverride
没有效果,即没有检测到单个缺失的@Override
注释。
解决方案
该MissingOverride
模块的文档指出:
当存在 {@inheritDoc} javadoc 标记时,验证 java.lang.Override 批注是否存在。
换句话说,它不打算检查您希望它检查的内容 - 它只检查{@inheritDoc}
Javadoc 注释中标记的使用是否与注释配对@Override
。
推荐阅读
- javascript - Javascript - 未选中 Radio 输入时更改元素内容
- javascript - 使用 JavaScript 向数组添加输入(最小值)
- python - 如何识别目录中的文件
- javascript - 如何将一个变量与对象数组中的另一个变量进行比较?
- c - scanf“最大字段宽度”包括空格?
- node.js - 将猫鼬模式存储在数据库中
- java - 为什么这个十六进制值得到不同的十进制值?
- mongodb - Mongodb Lookup 无法正常工作
- ios - 如何使 iOS UIPicker 与多个列和标题进行本机反应?
- postgresql - 是否可以在不破坏现有数据库的情况下重新安装 Postresql?