News for hackers. Stuff that matters.
Re:Modern programming languages require generics by mrighele on Tuesday May 24, 2022 @04:58PM (#31497476)
The example you provide has little to do with generics, but how inheritance works.

In particular if you override a method in a derived class, you're allowed to return an instance of a more specific class (in your example, Bar is an Object so it is fine). At runtime, your example is equivalent to something like

    interface Supplier {
        Object get();
    }

    class Foo extends Supplier {
        Bar get() { return new Bar(); }
    }

There are no comments on this comment yet.