In Swift it's very easy to write asynchronous methods chaining using Closure:
class AsyncTester {
class Server {
func asyncMethod(completionHandler : ((response : String) -> Void)) -> Void {
// completionHandler will be triggered asynchronously when server response returned
}
}
func asyncMethod(completionHandler : ((response : String) -> Void)) -> Void {
var server = Server()
server.asyncMethod(completionHandler)
}
func test() {
asyncMethod({ response in
println("got async resposne \(response)")
})
}
}
I know the equivalent in Java 8 for Closure is Lambda, I wonder how simplest implementation WITHOUT using Lambda should look like.
Using interface & anonymous classes as mentioned above.