4 ms·
Yes... but I think the real question that will stump people is "What is <? super Foo> and how is it different from <? extends Foo>". :D Java generic semantics
by cogman10 3y ago
Yes... but I think the real question that will stump people is "What is <? super Foo> and how is it different from <? extends Foo>". :D
Java generic semantics are wild and often surprising.
But too your point, I think typescript is FAR more complex than C++ yet I almost never see similar complaints of its complexity. The richer the type system, the more complex the language.
- jcranmer 3y agoThat's not the real confusing one in generics. The real confusing one is "What is the difference between Class<List> and Class<List<?>>" (i.e., mixed generics and raw types)... I only know about this because it bit me in the ass once!
- cogman10 3y agoHa! I thought about doing a tricky thing with wildcards vs missing generics. What gets even more wild is, for reasons I really don't understand, when a missing generic makes its way into a generic pipeline it seems to have the tendency to erase other generics. (IE, `list.stream().map((f)->new Map())` does weird things with the stream as it gets more complex.). You can throw in "What's the difference between List<Object>, List<?>, List, and List<? extends Object>" for good measure :D
- deleted 3y ago[deleted]
- charcircuit 3y ago>I think the real question that will stump people is "What is <? super Foo> and how is it different from <? extends Foo>" No, I don't think so. These are both common to see especially since Java 8 added Consumer as the former used to be pretty rare to see.
- tsimionescu 3y agoThese are both pretty intuitive - you can provide any class which is extended by or extends T respectively. Some of the consequences are less intuitive, but I don't think it's any hard to remember. As someone who last professionally programmed Java during Java 7 days, it was still clear to me what these mean.