Reputation: 301
Hello I am new to Kotlin, I wanna know how am I supposed to provide class Instance parameter to Kotlin Function
This is my Java code
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) {
}
});
Now in kotlin there's no new
keyword, so how do I supply new JsonHttpRepsonseHandler()
to kotlin function
kotlin function is:
Auth_REST_API_Client.GET(
"URL",
null,
JsonHttpResponseHandler() {
}
)
getting error at JsonHttpResponseHandler()
Upvotes: 0
Views: 186
Reputation: 30745
To create an object of an anonymous class that inherits from some type (or types), use object
keyword:
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) {
}
})
Upvotes: 3