JodaTime has
public final class DateTime extends BaseDateTime {...}
which works its way up to
public interface ReadableInstant extends Comparable<ReadableInstant>
Hamcrest has
public static <T extends java.lang.Comparable<T>> org.hamcrest.Matcher<? super T>
greaterThan(T value) {...}
If I try
greaterThan(new DateTime());
then I get a compile error (Eclipse gives most clue)
The generic method greaterThan(T) of type Matchers is not applicable
for the arguments (DateTime). The inferred type DateTime is not a valid substitute
for the bounded parameter >
Am I right in thinking that the signature of greaterThan should actually be
public static <T extends java.lang.Comparable<? super T>> org.hamcrest.Matcher<? super T>
greaterThan(T value)
? And is there a way to fit these together short of casting to the raw Comparable?
Yes, it looks to me like that would be a better signature.
Have you tried specifying the comparison type explicitly?
I don’t believe you can call it using a static import and also specifying the type argument, unfortunately – but that may not be too much of hardship.
Of course an alternative is to cast the argument:
I don’t have Hamcrest handy, but the above worked fine for me using the signature you’d given me, in a test type.