Why are contravariant parameter types in Java not allowed for overriding?

Because that’s called overloading.

In particular, the return type type can be covariant because it is not considered when overloading, and it therefore still matches the superclass or interface’s implementation. Parameters are considered when overloading. You very well might have an optimization with Number doSomethingWithNumber(Integer value) compared to Number doSomethingWithNumber(Number value).

Leave a Comment