@code java 注释有什么作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19302183/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What does the @code java annotation do
提问by JMS
I tried searching through the Oracle documentation for an explanation of what the
@code
java annotation does.
我尝试搜索 Oracle 文档以解释
@code
java 注释的作用。
From a previous question, I realized that it has something to do with html, but I'm not sure exactly what...
从上一个问题,我意识到它与 html 有关,但我不确定到底是什么......
Would it be correct to say that by default javadoc is parsed as HTML...
But placing the @code
annotation next to some javadoc text will indicate that it should be treated as code, and not parsed/rendered in the usual way?
So for example:
说默认情况下 javadoc 被解析为 HTML 是否正确......但是将@code
注释放在某些 javadoc 文本旁边将表明它应该被视为代码,而不是以通常的方式解析/呈现?例如:
/**
*This is how to declare an int variable {@code int var=1;}
*/
Would that be a proper example of its use?
这会是它使用的正确例子吗?
采纳答案by dkatzel
{@code ...}
is a Javadoc tag that tells Javadoc that the text inside the braces is source code and should not be treated as HTML. Javadoc should also format the text in a code block differently than the other text. This is a similar concept to the "code sample" text that the editor for StackOverflow uses when you format a question or answer.
{@code ...}
是一个 Javadoc 标记,它告诉 Javadoc 大括号内的文本是源代码,不应被视为 HTML。Javadoc 还应该将代码块中的文本格式化为与其他文本不同的格式。这与 StackOverflow 编辑器在您格式化问题或答案时使用的“代码示例”文本类似。
Javadocs are specially-formatted source code comments for class descriptions, constructors, and methods to help generate HTML documentation about source code. For example the Java API is fully documented using Javadocs for reading onlineor in an IDE. See the Java API Documentation Generatorfor details.
Javadoc 是用于类描述、构造函数和方法的特殊格式的源代码注释,可帮助生成有关源代码的 HTML 文档。例如,Java API 是使用 Javadocs在线或在 IDE 中阅读的完整文档。有关详细信息,请参阅Java API 文档生成器。
回答by The_Lost_Avatar
If you want to add JavaDocs for a method. Maybe you don't know what are Javadocs
如果要为方法添加 JavaDoc。也许你不知道什么是 Javadocs
So the thing in yellow is a Javadoc here
If you want to add code for a method as a Javadoc then you can annotate it with @code
for others using the method to see the method as an example.
and why we need to use it because if we don't do then the formatting won't be proper
所以黄色的东西是这里的Javadoc 如果您想将方法的代码添加为Javadoc,那么您可以@code
使用该方法对其进行注释,以查看该方法作为示例。以及为什么我们需要使用它,因为如果我们不这样做,那么格式将不正确
You can refer to following question if you want to check the changes in formatting that take place if you don't add the @code
: Multiple line code example in Javadoc comment
如果您想检查在不添加以下内容时发生的格式更改,您可以参考以下问题@code
:Javadoc 注释中的多行代码示例