如何记录 Kotlin 数据中的属性 class?
How to document attributes in Kotlin data class?
我应将 JavaKotlin 数据中属性的文档放在哪里 class?
换句话说,如何在 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)
但是属性文档放在哪里?
如 documentation 中所述,您可以为此使用 @property
标签:
/**
* Represents a person.
* @property firstName The first name.
* @property lastName The last name.
*/
data class Person(val firstName: String, val lastName: String)
或者,如果您在文档中对它们没有太多要说的话,只需在 class 的描述中提及 属性 名称:
/**
* Represents a person, with the given [firstName] and [lastName].
*/
data class Person(val firstName: String, val lastName: String)
我应将 JavaKotlin 数据中属性的文档放在哪里 class?
换句话说,如何在 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)
但是属性文档放在哪里?
如 documentation 中所述,您可以为此使用 @property
标签:
/**
* Represents a person.
* @property firstName The first name.
* @property lastName The last name.
*/
data class Person(val firstName: String, val lastName: String)
或者,如果您在文档中对它们没有太多要说的话,只需在 class 的描述中提及 属性 名称:
/**
* Represents a person, with the given [firstName] and [lastName].
*/
data class Person(val firstName: String, val lastName: String)