![](/img/trans.png)
[英]How to create an instance of a class and override its function in Kotlin?
[英]How to supply class instance as a parameter to Kotlin Function
您好,我是 Kotlin 的新手,我想知道我應該如何提供 class 實例參數給 Kotlin Z86408593C34AF52FDDZ
這是我的 Java 代碼
Auth_REST_API_Client.GET("URL", null, new JsonHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
}
@Override
public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) {
}
});
現在在 kotlin 中沒有new
的關鍵字,那么我如何向 kotlin function 提供new JsonHttpRepsonseHandler()
kotlin function 是:
Auth_REST_API_Client.GET(
"URL",
null,
JsonHttpResponseHandler() {
}
)
在JsonHttpResponseHandler()
處出錯
要創建繼承自某種(或多種)類型的匿名 class 的 object,請使用object
關鍵字:
Auth_REST_API_Client.GET("URL", null, object : JsonHttpResponseHandler {
override fun onSuccess(statusCode: Int, headers: Array<Header>, response: JSONObject) {
}
override fun onFailure(statusCode: Int, headers: Array<Header>, throwable: Throwable, response: JSONObject) {
}
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.