On Fri, Jan 17, 2025 at 7:50 PM David Alayachew <davidalayac...@gmail.com> wrote:
> I guess my next question is, there is no bridge method, which is why this > fails. Why not add a bridge method? What is stopping Java from doing this? > In Java class files it's possible to have two methods that differ only in their return type, but that's not allowed in Java source files (you'll get a "method already defined" error). So the only way bridge methods can be created is if the compiler adds them itself. When you override a superclass instance method with a narrower (covariant) return type, this is what happens automatically on your behalf. Static methods are also "inherited" by subclasses but there isn't the same concept of "overriding" - instead there is "hiding". So the compiler adding bridge methods would be inappropriate - or at the very least, they would change the semantics of the language incompatibly. -Archie -- Archie L. Cobbs