In Java 6 something like MyClass
and MyClass<?>
were considered equal but in Java 7 they are not.
With Java 7, as an example I stumble to problems with for example Hamcrest matchers that are given an instance of MyClass
and a matcher that expects to match MyClass<?>
, and they get compilation error saying
no suitable method found for assertThat(MyClass,Matcher<MyClass<?>>)
[ERROR] method Assert.<T#1>assertThat(T#1,Matcher<? super T#1>) is not applicable
[ERROR] (actual argument Matcher<MyClass<?>> cannot be converted to Matcher<? super MyClass> by method invocation conversion)
Why the change? What's the difference here between a rawtype and a generics type that has unspecified type argument?
Suggested answer does not really explain what I wonder here. One of the comments says "use of unbound wildcard (e.g. in a method signature) signals a promise that the method in question is aware of generics and will honor the generic type of that object." Here, again, I feel if it's just a "signal" it should not cause problems at compilation time.
I feel that MyClass<?>
is just MyClass
with information on what it contains or operates on, but while it's <?>
, there's no added information and so they should be considered equal?