I have the following available methods in a Utils
class:
protected <U> U withTx(Function<OrientGraph, U> fc) {
// do something with the function
}
protected void withTx(Consumer<OrientGraph> consumer) {
withTx(g -> {
consumer.accept(g);
return null;
});
}
And in a method of myClass
I have:
withTx(g -> anotherMethod(g));
The second piece of code has a compilation error:
The method withTx(Function<OrientGraph, Object>) is ambiguous for the type myClass
I guess this comes from the compiler, which is not able to determine if the lambda is a Consumer
or a Function
. Is there a noble way to disambiguate this situation?
Whatever the method anotherMethod
returns (void
, Object
, anything), I don't want to use this return value.
One solution is to do:
withTx(g -> { anotherMethod(g); });
But I wanted to know if there was something better, because this triggers SonarLint
.