The method signature says "you can set T to any ControlGraphic subclass", and therefore the purpose of typechecks (because the compiler finds a type T that works, in fact the type is taken from the assigned variable).
The "other" (direct loop) does not work, because type T can be any subclass of ControlGraphic, not necessarily PrecisionControlGraphic. The direct loop does not work, because type checking in Java does not make full output, as in functional programming languages. The variable type “graph” would literally have to be “any subclass of ControlGraphic” in order for it to be accepted (and this could actually be organized by making the type a parameter of the type of the attached method).
Another possibility, as @Adrian Leonhard pointed out, is to annotate a getGraphics call with the type you want:
for (PCG graph : this.<PCG>getGraphics())
But, basically, with any of these solutions you are abusing generics. All you know about getGraphics is that you are dealing with ControlGraphic objects, and so the method should return a List<ControlGraphic> , and your code should explicitly cast in places in the code that the derived type is known for.
source share