Reputation: 11
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:
private <T> String getEnumValues(Enum<? extends T>[] e) {
StringBuilder sb = new StringBuilder();
String sep = "";
for (Enum<? extends T> v : e) {
sb.append(sep);
sb.append(v.name());
sep = "|";
}
return sb.toString();
}
Upvotes: 0
Views: 1668
Reputation: 411
Enum itself is generic (in pure Java) with restriction on the parameter T
so:
`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
.
So you have to restrict T
in your code as well:
private <T extends Enum<T>> String getEnumValues(Enum<? extends T>[] e) {
StringBuilder sb = new StringBuilder();
String sep = "";
for (Enum<? extends T> v : e) {
sb.append(sep);
sb.append(v.name());
sep = "|";
}
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.
I see, it's not your code. So probably some older Java didn't check this properly.
Upvotes: 2