Why ”Type Bound mismatch: The type ? extends T is not a valid substitute for the bounded parameter <E extends Enum> of the type Enum“?
Clash Royale CLAN TAG#URR8PPP
Why ”Type Bound mismatch: The type ? extends T is not a valid substitute for the bounded parameter <E extends Enum<E>> of the type Enum<E>“?
I am trying to read the hadoop 1.0.0 source code in eclipse. I downloaded the source code first and then use ant eclipse
to build the project. After that, I successfully created the project in eclipse. But there is an error Type Bound mismatch: The type ? extends T is not a valid substitute for the bounded parameter <E extends Enum<E>> of the type Enum<E>
on the line 396 of Gridmix.java
. The error code:
ant eclipse
Type Bound mismatch: The type ? extends T is not a valid substitute for the bounded parameter <E extends Enum<E>> of the type Enum<E>
Gridmix.java
private <T> String getEnumValues(Enum<? extends T> e)
StringBuilder sb = new StringBuilder();
String sep = "";
for (Enum<? extends T> v : e) ";
return sb.toString();
I am using jdk 1.8 now. I will try jdk 1.6.
– windkl
Aug 8 at 7:03
Why Hadoop 1.x? Have you compared that class to Hadoop 3?
– cricket_007
Aug 8 at 12:53
I have solved the problem now. Thanks to Patrick Parker. If I use jdk 1.6 and eclipse Kepler, there will be no errors.
– windkl
Aug 8 at 13:56
I just want to learn the source codes of Hadoop but the newest version is too complex. so I choose the older version.
– windkl
Aug 8 at 13:58
1 Answer
1
Enum itself is generic (in pure Java) with restriction on the parameter T
so:
T
`Enum<T extends <Enum<T>>`
You don't have any restriction on T in your code, so compiler complains, because You may end up with T = Object
, but Enum
cannot accept Object
as T
.
T = Object
Enum
Object
T
So you have to restrict T
in your code as well:
T
private <T extends Enum<T>> String getEnumValues(Enum<? extends T> e)
StringBuilder sb = new StringBuilder();
String sep = "";
for (Enum<? extends T> v : e) ";
return sb.toString();
In fact in this case the wildcard wouldn't make sense, because you cannot extend T
(because you cannot extend any specific enum
). But that should already compile. If not, drop the wildcard.
T
enum
I see, it's not your code. So probably some older Java didn't check this properly.
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
do you know what version of Java you are building with? make sure it is compatible
– Patrick Parker
Aug 8 at 6:56