簡體   English   中英

如何在 KDoc 中引用輔助構造函數?

[英]How do I reference a secondary constructor in KDoc?

我有一個帶有輔助構造函數的 Kotlin class,它應該用於特定場景。 現在這應該從第一個構造函數中正確記錄,以便您可以立即看到它。

/**
* This is my class.
* 
* @constructor This is the primary constructor meant for Scenario A.
* If you are in Scenario B, please use [reference to secondary constructor] <- what do I put in here?
*/
class MyClass(val a: String) {

    constructor(b: Int) : this("$b abc")

}

我一點也不知道在方括號中放什么用於引用成員/函數,但我覺得應該是可能的。 如果有人對此了解更多,那就太好了

您不必引用第二個構造函數,編譯器會根據您的參數為您執行此操作。 如果你想要一個不同的構造函數,或者如果你只使用特定的屬性,只需創建一個新的 class,你可以在 class 聲明中使用*來只使用給定的參數。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM