简体   繁体   English

@code java 注释有什么作用

[英]What does the @code java annotation do

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?说默认情况下 javadoc 被解析为 HTML 是否正确...但是将@code注释放在一些 javadoc 文本旁边将表明它应该被视为代码,而不是以通常的方式解析/呈现? So for example:例如:

    /**
    *This is how to declare an int variable {@code int var=1;}
    */

Would that be a proper example of its use?这会是它使用的适当例子吗?

{@code ...} is a Javadoc tag that tells Javadoc that the text inside the braces is source code and should not be treated as HTML. {@code ...}是一个Javadoc标记,它告诉Javadoc大括号内的文本是源代码,不应该被视为HTML。 Javadoc should also format the text in a code block differently than the other text. Javadoc还应该以不同于其他文本的方式格式化代码块中的文本。 This is a similar concept to the "code sample" text that the editor for StackOverflow uses when you format a question or answer. 这与StackOverflow编辑器格式化问题或答案时使用的“代码示例”文本类似。

Javadocs are specially-formatted source code comments for class descriptions, constructors, and methods to help generate HTML documentation about source code. Javadocs是特殊格式的源代码注释,用于类描述,构造函数和方法,以帮助生成有关源代码的HTML文档。 For example the Java API is fully documented using Javadocs for reading online or in an IDE. 例如,使用Javadocs 在线阅读或在IDE中完整记录Java API。 See the Java API Documentation Generator for details. 有关详细信息,请参阅Java API文档生成器

If you want to add JavaDocs for a method. 如果要为方法添加JavaDocs。 Maybe you don't know what are Javadocs 也许你不知道什么是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. 所以黄色的东西是Javadoc这里如果你想为一个方法添加代码作为Javadoc然后你可以使用@code为其他人使用该方法来注释它以查看方法为例。 and why we need to use it because if we don't do then the formatting won't be proper 以及为什么我们需要使用它,因为如果我们不这样做,那么格式化将不合适

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注释中的多行代码示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM