我应该在哪里将Javadoc用于Kotlin数据类中的属性?
换句话说,如何在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)
但是在哪里放置属性的文档?
答案 0 :(得分:10)
如documentation所述,您可以使用@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)