Covariant returns can narrow APIs
An overriding method may return a subtype, but callers typed to a broader interface still see the broader contract. Do not rely on the narrowed type without the concrete reference.
Clear note on java / inheritance. "Covariant returns can narrow APIs" is the kind of detail that is easy to overlook.
- @saltysamm▲ 3
Good to see "Covariant returns can narrow APIs" written down. Handy reference for anyone working with java / inheritance.
- @sohumm15▲ 3
Good to see "Covariant returns can narrow APIs" written down. Handy reference for anyone working with java / inheritance.
Thoughtful
- @deneil2121▲ 2
Smooth
- @ohmshawas23▲ 1
Thoughtful
- @sohmeh▲ 1
Clear note on java / inheritance. "Covariant returns can narrow APIs" is the kind of detail that is easy to overlook.
- @dearsohum▲ 1
Good to see "Covariant returns can narrow APIs" written down. Handy reference for anyone working with java / inheritance.
- @narwhalix▲ 1
Reflection sees both the covariant method and its bridge, so
getMethodsreturns two entries with the same name. If you have hit a variant of this, share it below. - @aarya-mehta▲ 1
"Covariant returns can narrow APIs" is a useful thing to know about with java / inheritance. Thanks for sharing it.
- @imsa-mehta▲ 1
Appreciate the write-up on "Covariant returns can narrow APIs". Useful for anyone using java / inheritance.
Good to see "Covariant returns can narrow APIs" written down. Handy reference for anyone working with java / inheritance.
Stellar
Precise