Re:Modern programming languages require generics
by marginalia_nu on Tuesday May 24, 2022 @01:03PM
(#31494692)
Bar isn't a generic in Foo though (if we remove the implements-clause, that is very clear). It's only a generic in Supplier, so I don't see where the implied erasure quite comes from.
[ Parent
| on HN ]
Re:Modern programming languages require generics
by cogman10 on Tuesday May 24, 2022 @01:10PM
(#31494786)
I didn't add it, but the `get` method comes is an override from the `Supplier`.
For example, if we did something like
class Foo extends HashMap<Foo, Bar> {
@Override
Bar put(Foo f, Bar b) {
super.put(f, b);
}
}
The `Map` signature for `put` is `Object put(Object, Object)` due to erasures. However, because you are extending and specifying the generics, the overriden method ends up reifying the type.All this is to say that generics end up being a little more than just syntactic sugar.
Re:Modern programming languages require generics
by marginalia_nu on Tuesday May 24, 2022 @01:20PM
(#31494920)
If you consider this example:
class Base<T> {
T f() { return null; }
}
class A<T2> extends Base<T2> {
@Override
T2 f() { return null; }
}
class B extends Base<Integer> {
@Override
Integer f() { return null; }
}
class C {
Integer f() { return null; }
}
Base has a parameter T which is erased in Base.A has a parameter T2 which is erased in A.
B because B is not a generic class and nothing is erased from B.
Base has the same shape as A; B has the same shape as C.