Open garretwilson opened 2 years ago
Interestingly I can create a workaround simply by adding this method inside the test itself!
public static <T> Matcher<? super Optional<T>> isPresentAndIs(T operand) {
return OptionalMatchers.isPresentAndIs(operand);
}
Apparently there is just some type inference that Java just can't handle without help.
Thanks for your library, which I have been using for many years.
I just run into a problem with nested generics inside
Optional<>
. Let's say I have a method that returns anOptional<Map<Integer, BigDecimal>>
:I try to test it like this:
This doesn't compile on Eclipse 2022-06 using Java 17. It gives me:
Because the second argument in
assertThat()
usesMatcher<? super T>
, apparently it doesn't realize that oneOptional<Map<Integer,BigDecimal>>
is equivalent to another. (If I haven't interpreted this correctly, let me know.)The signature to
isPresentAndIs()
is:If I change it to the following, the test will compile:
I think you need a bunch of
? super
sprinkled throughout your API.