16

Kotlin 数据类中属性的 Javadoc 应该放在哪里?

换句话说,如何在 Kotlin 中编写以下 Java 代码:

/**
 * Represents a person.
 */
public class Person {
    /**
     * First name. -- where to place this documentation in Kotlin?
     */
    private final String firstName;
    /**
     * Last name. -- where to place this documentation in Kotlin?
     */
    private final String lastName;

    // a lot of boilerplate Java code - getters, equals, hashCode, ...
}

在 Kotlin 中,它看起来像这样:

/**
 * Represents a person.
 */
data class Person(val firstName: String, val lastName: String)

但是在哪里放置属性的文档?

4

1 回答 1

23

文档中所述,您可以@property为此使用标签:

/**
 * Represents a person.
 * @property firstName The first name.
 * @property lastName The last name.
 */
data class Person(val firstName: String, val lastName: String)

或者,如果您在文档中对它们没有太多要说的话,只需在类的描述中提及属性名称:

/**
 * Represents a person, with the given [firstName] and [lastName].
 */
data class Person(val firstName: String, val lastName: String)
于 2018-04-05T14:35:34.933 回答