android - 如何将类实例作为参数提供给 Kotlin 函数
问题描述
您好我是 Kotlin 的新手,我想知道我应该如何为 Kotlin 函数提供类实例参数
这是我的 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
关键字,那么我如何提供new JsonHttpRepsonseHandler()
给 kotlin 函数
kotlin 函数是:
Auth_REST_API_Client.GET(
"URL",
null,
JsonHttpResponseHandler() {
}
)
出现错误JsonHttpResponseHandler()
解决方案
要创建从某种(或多个类型)继承的匿名类的对象,请使用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) {
}
})
推荐阅读
- android - 如何使用 ViewPager2 删除 TabLayout 上的滚动条?
- python - KeyError:“['belongs_to_collection' 'homepage' 'original_title' 'overview'\n 'poster_path' 'status' 'tagline'] 在轴中找不到”
- python - DataFrame - 追加结果并求和
- excel - IF 公式作为 VBA 复制和粘贴的一部分
- java - 不要为基本类型(如字符串、数组、基元和盒装基元)建议 'var' 类型
- sql - 如果 secord_table 中根本没有记录,如何使用 `where second_table.key!='value'` 进行左连接
- reactjs - 为什么我会收到此错误?TypeError:this.state.items.sort 不是函数
- jquery - 在 jquery 中禁用浏览器弹出窗口阻止程序
- python - 将numpy数组中的单个值提取到列表中
- sql - 链接第三张桌子