Java Interface Objects in Kotlin
Consider I have an interface like the one below:
interface JSONObjectRequestListener {
fun onSuccess()
fun onFailure()
}
Now I have a method in my MainActivity:
fun onRequestHappen(listener: JSONObjectRequestListener)
If this were java, I would have passed this object as:
onRequestHappen(new JSONObjectRequestListener() {
@Override
public void onResponse() {
// do anything with response
}
@Override
public void onError() {
// handle error...