我有以下改造单身人士:
interface MyAPI
{
    @GET("/data.json")
    suspend fun fetchData() : Call<MyResponse>
    companion object
    {
        private val BASE_URL = "http://10.0.2.2:8080/"
        fun create(): MyAPI
        {
            val gson = GsonBuilder()
                .setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ")
                .create()
            val retrofit = Retrofit.Builder()
                .addConverterFactory( GsonConverterFactory.create( gson ) )
                .baseUrl( BASE_URL )
                .build()
            return retrofit.create( MyAPI::class.java )
        }
    }
}
MyResponse.kt
data class MyResponse(
    val listOfData: List<DataEntity>
)
数据实体.kt
data class DataEntity(
    @SerializedName("name")
    val fullName: String
}
我通过以下方式从 ModelView 调用代码:
viewModelScope.launch {
    try {
        val webResponse = MyAPI.create().fetchData().await()
        Log.d( tag, webResponse.toString() ) …我有一个带有辅助构造函数的 Kotlin 类,应该在特定场景中使用。现在这应该从第一个构造函数中正确记录下来,以便您可以立即看到它。
/**
* 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")
}
我不知道在用于引用成员/函数的方括号中放什么,但我觉得这应该是可能的。如果有人对此了解更多,那就太好了