我正在写一个科特林图书馆。在其中一个课程中,我有以下内容:
class SessionWrapper {
/**
* The time in milliseconds after which the session will expire.
*/
var expiryTime = DEFAULT_EXPIRY_TIME
get() {
mainThreadCheck()
return field
}
set(value) {
mainThreadCheck()
field = value
updateExpiry(value) <<< THIS ONE
}
...
}
然而
updateExpiry(long)
具有对客户透明的行为
SessionWrapper
,如果修改
expiryTime
(即打电话给设定者)。
现在,对于Kotlin项目,这不会是一个问题,因为我可以将额外的KDoc添加到
到期时间
财产本身,而且不会觉得不合适:
/**
* The time in milliseconds after which the session will expire.
*
* Updating the expiry time after the session is started does x,
* the listeners will receive y.
*
* Writing comments is fun, when the tools work.
*/
var expiryTime = DEFAULT_EXPIRY_TIME
但对于Java项目,上面的文档将同时显示
setExpiryTime(long)
和
getExpiryTime()
感觉不舒服,因为我会
getter中的setter JavaDoc和setter中的getter JavaDoc
。
尝试以以下方式在Kotlin中分离两个访问者的文档:
class SomeClass{
var expiryTime = DEFAULT_EXPIRY_TIME
/**
* The time in milliseconds after which the session will expire.
*/
get() {
mainThreadCheck()
return field
}
/**
* Updating the expiry time after the session is started does x,
* the listeners will receive y.
*
* Writing comments is fun, when the tools work.
*/
set(value) {
mainThreadCheck()
field = value
updateExpiry(value)
}
...
}
只是在IDE中没有显示JavaDoc,对于Kotlin和;Java代码。
我没有找到明确的方法来分离Java visible getters的文档;中的setters
KDoc reference
或者
Java interop page
。
考虑到Kotlin与Java的良好互操作性,我觉得这很烦人。
如果您有任何想法,我将不胜感激。