Skip to content

Change generic signature of OrderingComparison to accept Comparable<? super T> - #43

Closed
nhinds wants to merge 1 commit into
hamcrest:masterfrom
nhinds:ordering_comparison_widen_generics
Closed

nhinds wants to merge 1 commit into
hamcrest:masterfrom
nhinds:ordering_comparison_widen_generics

Conversation

@nhinds

@nhinds nhinds commented Dec 9, 2013

Copy link
Copy Markdown

Currently to use OrderingComparison with classes which extend other comparable classes (or in general, classes which are comparable to one of their supertypes), the argument needs to be explicitly cast to the supertype, e.g.

ConcreteType myObj1, myObj2;
assertThat(myObj1, greaterThan((AbstractType)myObj2);

This patch changes the generic signature of OrderingComparison to accept T extends Comparable<? super T>, which should be compatible with existing uses but also allow more valid cases to compile.

@pgelinas

pgelinas commented Jan 2, 2014

Copy link
Copy Markdown

+1. Also, Effective Java states to "always use Comparable<? super T> in preference to Comparable" in Chapter 5 (Item 28)

@npryce npryce added this to the 7.0 milestone Dec 24, 2014
@npryce npryce self-assigned this Dec 24, 2014
npryce added a commit that referenced this pull request Dec 24, 2014
…t Comparable<? super T>) and re-implement for new OrderingComparison/ComparatorMatcherBuilder mechanism.
npryce added a commit that referenced this pull request Dec 24, 2014
…t Comparable<? super T>) and re-implement for new OrderingComparison/ComparatorMatcherBuilder mechanism.
@npryce

npryce commented Dec 24, 2014

Copy link
Copy Markdown
Contributor

Merged into v7.0 branch

@npryce npryce closed this Dec 24, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants