首页 > 解决方案 > Checkstyle:单行 Java 注释在两个斜杠后是否应该有空格?

问题描述

似乎没有默认的 Checkstyle 检查,也没有默认的 Google Checkstyle 检查来确保单行注释的格式如下:

// comment text

而不是这样:

//comment text

Java 语言规范的第 3.7 节“注释”中暗示了此约定:

3.7. 注释

有两种评论:

/* text */

A traditional comment: all the text from the ASCII characters /* to the ASCII characters */ is ignored (as in C and C++).

// text

An end-of-line comment: all the text from the ASCII characters // to the end of the line is ignored (as in C++).

总而言之,它似乎是Java本身的必要条件,例如在http://hg.openjdk.java.net/jdk7u/jdk7u6/jdk/file/8c2c5d63a17e/src/share/classes/java/lang/String.java

这是一致的,因此显然是经过深思熟虑的。

因此,省略两个斜线和评论文本之间的空格在客观上是不正确的吗?

是否有一个著名的 Checkstyle 检查扩展库,其中包含对此的检查?

标签: javacommentscheckstyle

解决方案


推荐阅读