When I try to use something like this
class Example {
...
private Future<String> asyncMethod() {
...
return somePromise;
}
private static void callback(Future<String> future) {
System.out.println(future.getNow());
}
public static void main(String[] args) {
asyncMethod().addListener(Example::callback);
}
}
I get an error
Example.java:[17,34] incompatible types: invalid method reference
incompatible types: io.netty.util.concurrent.Future<capture#1 of ? super java.lang.String>
cannot be converted to io.netty.util.concurrent.Future<java.lang.String>
There are no errors with an anonymous class as the listener
asyncMethod().addListener(new GenericFutureListener<Future<String>>() {
@Override
public void operationComplete(Future<String> future) throws Exception {
System.out.println(future.getNow());
}
});
But it's ugly and verbose :( What can I do to solve this problem in the most elegant way?