I can't understand why the following code works: Sam Interface:
fun interface WebResponseHandler
{
fun onWebResponseFinished(jsonObject:JSONObject)
}
and Implemnetaiton looks like:
val onWebResponseHandler: VolleyHandler.WebResponseHandler = VolleyHandler.WebResponseHandler()
{
fun onWebResponseFinished(jsonObject: JSONObject) {
Log.v("da", "dsa")
}
fun foo() {
it.getString("name")
}
}
How does foo function knows what is it? After all, foo function isn't part of the VolleyHandler.WebResponseHandler interface, and it works only when interface as only one method.Function Foo is being called without any arguments, so why is the meaning of it there?
In addition another problem occurs if I'm omitting the keyword fun from the interface declaration, when i'm trying to implement the interface:
val onWebResponseHandler: VolleyHandler.WebResponseHandler = VolleyHandler.WebResponseHandler()
{
fun onWebResponseFinished(jsonObject: JSONObject) {
Log.v("da", "dsa")
}
fun foo() {
Log.v("something", "something")
}
}
I'm getting a compilation error saying
Interface WebResponseHandler does not have constructors
what is the different between both situation? If i remove the () i'm getting a lot of different errors like :
Function declaration must have a name
I hope someone can figure out what is wrong here