Java 中的内联注释:/** 与 /* 相对?
我是否应该更喜欢在 java 中编写内联注释,如下所示:
/** Init operation */
mindControlLaser.engage();
而不是仅使用一个 *:
/* i'm a happy comment */
Eclipse 以不同的方式对语法进行着色,但是“工具链”(javadoc、eclipse 等)中是否真的有任何东西可以提供使用 /** */ 时我有一个优势?
is there a reason i should prefer to write inline-comments in java like this:
/** Init operation */
mindControlLaser.engage();
as opposed to use just one *:
/* i'm a happy comment */
Eclipse colours the syntax differently, but is there really anything in the "toolchain" (javadoc, eclipse, etc.) giving me an advantage when using /** */ ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
没有理由进行内嵌评论。
/**
向 javadoc 实用程序发出信号,自动提取有关 API 的文档。在方法内部使用时它没有任何效果。No reason for inline comments.
/**
signals to javadoc utility to extract documentation about your API automatically. It does not have any effect when is used inside methods.常规注释
/* 常规注释 */
通过常规注释,您可能会解释算法中棘手的一部分。
或者任何您不想成为 JavaDOC 一部分的内容。内联注释也是常规注释,可以在描述较短时使用。
Java 文档
/** JAVA DOC COMMENT */
使用 javadoc,您可以解释类、方法或字段(变量)。
然后,大多数 IDE(例如 Eclipse)可以在您编码时使用此信息来帮助您。
例如,如果您有一个
classA
和一个classB
,并且在classB
中您使用了classA
中的内容,那么如果将鼠标悬停在方法或变量上,您可以看到 JavaDOC 信息。非常方便。此外,使用像
ant
这样的构建工具,您可以自动从 JavaDOC 构建 HTML 文件,如果您发布它们,您就可以允许其他人重用您的工作。请在此处查找 Java 本身的文档。
Regular comments
/* Regular comment */
With regular comments you explain maybe a part of an algorithm that is tricky.
Or anything that you don't want to be a part of the JavaDOC. Inline comments are regular comments too, and can be used for example when the description is shorter.
Java Documentation
/** JAVA DOC COMMENT */
With javadoc you explain classes, methods, or fields(variables).
Then, most IDEs like Eclipse can use this information to help you while you code.
For example, if you have a
classA
and aclassB
, and inclassB
you use stuff fromclassA
, then if you hover on methods or variables you can see the JavaDOC information. It's very handy.Also, with build tools like
ant
you can automatically build HTML files out of the JavaDOC, and if you publish them you can allow others to reuse your work.Look for example the documentation of Java itself here.
注释的语法是
/* */
。Javadoc 默认使用
/** */
。这是一条注释,因为第二个*
位于注释内,因此编译器不会有不同的看法。因此,如果没有第二个
*
,您只需添加一条注释,而使用第二个注释时,您将编写 javadoc:当将鼠标悬停在其他地方的函数调用上时,Eclipse 会识别它并给您提示等。The syntax for a comment is
/* */
.Javadoc has as a default that you use
/** */
. This is a comment because the second*
is inside the comment, so would not be seen differently by your compiler.So without a second
*
you are just adding a comment, and with the second one you write javadoc: eclipse will recognize it and give you hints etc when hovering on the functioncall somewhere else./** .... */
将生成 Javadoc,/* ... */
不会。当然,它只有在正确的位置才会生成Javadoc。 Javadoc 也有一个非常明确定义的格式,请参阅此处 。
/** .... */
will generate Javadoc,/* ... */
won't.Of course, it will generate Javadoc only when in the correct places. Javadoc also has a pretty well defined format, see here.
/**
表示“文档”注释; Javadocs 等在为代码创建文档时会查找这些内容。因此,它们实际上应该只在方法和类之上使用,例如:
/*
变体仅表示标准注释块。The
/**
denotes "documentation" comments; Javadocs etc. look for these when creating documentation for your code.So they should really only be used above methods and classes, e.g.:
The
/*
variant just denotes a standard comment block.是的,这是使用
/** 主句的 javadoc 表示法。其他描述... */
。.
之前的第一句话将用于 javadoc 的摘要中,其余部分将用于详细视图中。Yep, it's the javadoc notation to use
/** Primary sentence. Other descriptions... */
. First sentece up to the.
will be used in summaries of javadoc and the rest in the detailed view.Javadoc 对 /** 的处理方式不同;上面有 /** 注释的类和方法将被放入 javadoc 输出中。
Javadoc treats /** differently; classes and methods which have /** comments above them will get put into javadoc output.
如果您使用引用格式(例如
{@link ClassA}
)并使用Eclipse 重命名类ClassA
,如果它是javadoc 注释,它将自动更新注释。If you use the reference formatting (e.g.
{@link ClassA}
) and rename the classClassA
with Eclipse, it will automatically update the comment if it is a javadoc comment.