Compilation error due to ambiguous getOrElse on a lambda
Issue #34
resolved
Dealing with a snippet of code like the following in Java 8:
return someMethod(
someMethodThatReturnsAnOption().getOrElse(
() -> UUID.fromString(someMethodThatReturnsAString())
)
);
And getting a compilation of the following;
both method <B>getOrElse(B) in Option and method getOrElse(Supplier<? extends A>) in Option match
where B,A are type-variables:
B extends A declared in method <B>getOrElse(B)
A extends Object declared in class Option
MyClass:54: error: incompatible types: cannot infer type-variable(s) B
return someMethod(someMethodThatReturnsAnOption().getOrElse(() -> UUID.fromString(someMethodThatReturnsAString())));
Being explicit and casting it as so works, but is a bit ugly :) ->
return someMethod(
someMethodThatReturnsAnOption().getOrElse(
(Supplier<UUID>)() -> UUID.fromString(someMethodThatReturnsAString())
)
);
Relevant: http://stackoverflow.com/questions/21905169/java8-ambiguity-with-lambdas-and-overloaded-methods
Comments (2)
-
-
- changed status to resolved
Resolved after merging https://bitbucket.org/atlassian/fugue/pull-request/39/addition-of-getorelzelazily-to-avoid
- Log in to comment
https://bitbucket.org/atlassian/fugue/pull-request/39/addition-of-getorelzelazily-to-avoid