我应该使用 /* */ 或 /** */ 作为 java 文件顶部的版权吗?

发布于 2024-12-18 19:48:44 字数 239 浏览 5 评论 0原文

每个java文件中都有版权注释,但我不知道该使用哪一个:/* */还是/** */

 /*
  * Copyright ...
  */
 import java.util.*
 ...

或者

/**
 * Copyright ...
 */
import java.util.*
....

There is a copyright comment in each java file, but I don't know which one should I use: /* */ or /** */?

 /*
  * Copyright ...
  */
 import java.util.*
 ...

or

/**
 * Copyright ...
 */
import java.util.*
....

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

究竟谁懂我的在乎 2024-12-25 19:48:44

这个相当旧的(大约 1999 年)Sun 编码约定 文件建议 /* */

更具体地说,它建议您的类/接口文件采用以下布局:

  • 开始注释

    <前><代码>/*
    * 类名
    * 版本信息
    * 日期
    * 版权声明
    */

  • packageimport 语句
  • 类和接口声明(其中包括该类的 Javadoc 注释 - 请参阅表条目 #1)。

例子:

/*
 * MyClass
 *
 * v1.0
 *
 * 2011-11-29
 * 
 * This file is copyrighted in an awesome way.
 */
package com.example.mypackage;

import com.example.otherpackage;

/**
 * Javadoc comments for the class.
 */
public class MyClass {
    ...
}

This rather old (circa 1999) Sun coding conventions document suggests /* */.

More specifically, it suggests the following layout for your class/interface file(s):

  • Beginning comments

    /*
     * Classname
     * Version information
     * Date
     * Copyright notice
     */
    
  • package and import statements
  • Class and interface declarations (which includes Javadoc comments for the class - see table entry #1).

Example:

/*
 * MyClass
 *
 * v1.0
 *
 * 2011-11-29
 * 
 * This file is copyrighted in an awesome way.
 */
package com.example.mypackage;

import com.example.otherpackage;

/**
 * Javadoc comments for the class.
 */
public class MyClass {
    ...
}
唠甜嗑 2024-12-25 19:48:44

如果 /** ... */ 注释直接位于要记录的任何声明之前,Javadoc 只会收集它们。
package(package-info.java 中除外)和 import 声明无论如何都没有记录,因此 Javadoc 不会以任何一种方式查看注释。

由于这对于 Javadoc 来说并不重要,因此您也可以使用“较轻”的 /* ... */ 版本。

Javadoc will only gather /** ... */ comments if they are directly before any declaration to be documented.
package (other than in package-info.java) and import declarations are not documented anyway, so Javadoc will not look at the comment in either way.

As it doesn't matter for Javadoc, you can as well use the "less heavy" /* ... */ version.

锦上情书 2024-12-25 19:48:44

如果您使用 /** */ 文档工具会抓住它,所以您最好使用它:)

If you use /** */ documenting tools will grab it so you're better off using it :)

独守阴晴ぅ圆缺 2024-12-25 19:48:44

我刚刚看了一些开源java项目,发现它们都使用 /* */

I just read some open source java projects, found they all use /* */

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文