There is a method in hamcrest library:
package org.hamcrest.core
...
public static <T> Matcher<T> allOf(Matcher<? super T> first, Matcher<? super T> second) {
List<Matcher<? super T>> matchers = new ArrayList<Matcher<? super T>>(2);
matchers.add(first);
matchers.add(second);
return allOf(matchers);
}
In my code, I call this method with first
being Matcher<Object>
and second
being Matcher<SomeException>
.
And now:
- When I compile it with Eclipse with 1.6 target, it makes
<T>
Matcher<SomeException>
. - When I compile it with javac 1.7 with 1.6 target, it makes
<T>
Matcher<SomeException>
. - When I compile it with javac 1.6 with 1.6 target, it makes
<T>
Matcher<Object>
The question is, what <T>
should be in such case?
My understanding is, that there is a bug in javac 1.6 and it should be Matcher<SomeException>
, as this is a common type for input arguments (SomeException is a subtype of Object) and then, it is 100% sure, that returned Matcher will be Matcher<SomeException>
.
Am I right? And is there any way to force javac 1.6 to behave properly?