Async methods chaining in Java NOT using Lambda

322 views Asked by At

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.

1

There are 1 answers

0
Tamir On

Using interface & anonymous classes as mentioned above.