Reputation: 79
No Problems here
public class MyList<E extends Number> extends ArrayList<E> {
}
.
Unexcepted bound. What does this mean? And why is it wrong? Thanks for help.
public class MyList<E extends Number> extends ArrayList<E extends Number> {
}
Upvotes: 2
Views: 4819
Reputation: 353
public class MyList<E extends Number> extends ArrayList<E> {
private static final long serialVersionUID = -1025575227555594680L;
}
This should work with no compilation error and no warnings even. Let me know if you still have the same error.
Upvotes: 2
Reputation: 1484
class MyList<E extends Number>
is OK because you declare a type parameter, so you have to give it a name (E
) and you can optionally declare it as bounded (extends Number
).
In extends ArrayList<E>
instead you just have to "use" a type parameter: with "<E>
" you refer to the parameter declared in your class, for which a bound is already given in its declaration. "<? extends Number>
" (with ?
in place of E
) would also be accepted by the compiler (although it would be not what you want). Instead, "<E extends Number>
" is taken as a type parameter declaration, so it is a compile error.
Upvotes: 7