Please give me a hint about what is going on here:
List<? extends Number> a = new ArrayList<Number>(); List<? extends Number> b = new ArrayList<Number>(); a.addAll(b);
This simple code does not compile. I vaguely remember something related to type captures, for example, those that should be mainly used in the interface specifications, and not in the code itself, but I didn’t get fooled that way.
This, of course, can be fixed roughly, like this:
List<? extends Number> a = new ArrayList<Number>(); List<? extends Number> b = new ArrayList<Number>(); @SuppressWarnings({"unchecked"}) List<Number> aPlain = (List<Number>) a; @SuppressWarnings({"unchecked"}) List<Number> bPlain = (List<Number>) b; aPlain.addAll(bPlain);
So, do I really need to either abandon the captures in the ad (the capture came to me from the interface, so I have to change some kind of API), or stick to sizes with suppression annotations (which usually suck and complicate the code a bit)?
source share