Wildcard with final upper bound

Viewed 692

Class<? extends Integer> will compile fine, but Integer is a final type so it doesn't make sense to use it as an upper bound (nothing will ever extend it).

If you try to use a final type as an upper bound for a type parameter, you will get a compiler warning:

The type parameter T should not be bounded by the final type Integer. Final types cannot be further extended

Why would using a final type as an upper bound for a wildcard be perfectly fine, but throw a warning for a type parameter? Why does Java even allow for wildcards to be bounded by a final upper type?

1 Answers
Related