You cannot compile your example - you call the non-static getPercentiles method from a static initializer, so I also assume that it is also a static method.
In any case, your compiler at least spat out the "unchecked" warning if you compiled with -XLint:unchecked (Stat accepts a type parameter!). I assume you would like to:
public class X { interface Stat<T> { } public static void exportAll(Iterable<? extends Stat<? extends Number>> vars) { } public static Map<Double, ? extends Stat<Double>> getPercentiles() { return null; } static { exportAll(getPercentiles().values()); }
I assume your percentiles are an arbitrary subclass of Stat<Double> , so I declared them as ? extends Stat<Double> ? extends Stat<Double> on the Map. So calling values() returns Collection<? extends Stat<Double>> Collection<? extends Stat<Double>> .
Collection implements Iterable , so we are safe on this side. But Collection<? extends Stat<Double>> Collection<? extends Stat<Double>> not covered by Iterable<Stat<? extends Number>> Iterable<Stat<? extends Number>> , so we need to declare the argument as Iterable<? extends Stat<? extends Number>> Iterable<? extends Stat<? extends Number>> Iterable<? extends Stat<? extends Number>> .
The beauty (well, except the syntax) of having exportAll accepts Iterable<? extends Stat<? extends Number>> Iterable<? extends Stat<? extends Number>> Iterable<? extends Stat<? extends Number>> , is that your Map can contain all kinds of ? extends Stats<N> ? extends Stats<N> , where N is a subclass of Number .
source share