Home > database >  Lambda getResult()
Lambda getResult()

Time:02-17

I came across the following bit of code online which I can't figure it out:

mFoo.bar(future -> {
    Bundle result = future.getResult();
    boolean success = result.getBoolean(Foo.KEY_BOOLEAN_RESULT);
    if (success) {
        showToast("success");
    } else {
        showToast("failure");
    }
});

The bar method takes a callback argument, and a lambda expression is passed in. But I don't understand what this line is doing:

Bundle result = future.getResult();

Help would be appreciated. Thanks!

CodePudding user response:

You can tell the type of 'future' from the specification of 'bar()'. Presumably that type has a 'getResult()' that returns a 'Bundle'. What does the documentation say>

In general, a 'future' represents the eventual result of an asynchronous computation. For likely-similar functionality, see Future. There is a 'get()' method to block until the completion of the computation, and then return the result of that computation.

  • Related