I don't think there is a way to invoke an erasable version of a static method (in a clean assembly)
public static <L extends List<?> & RandomAccess> void do1(L list) {} private static <L extends List<?> & RandomAccess> L cast(Iterable<?> iterable) { return (L) iterable; } public static void do2(Iterable<?> iterable) { do1(cast(iterable));
We can call the erasable version of instance methods via raw type
static class Helper<T> { <T, L extends List<? extends T> & RandomAccess> void do3(L list) { do1(list); } } public static void do2(Iterable<?> iterable) { Helper helper = new Helper();
Return to static methods. Suppose we have this pre-Java5 code
#1 static void foo(List list){} #2 foo(new ArrayList());
now after java5, # 1 is generated as
#1 static void foo(List<?> list){}
but # 2 is kept as it is, with a raw type. How is it that number 2 is still compiling? The spectrum (15.12.2.2) allows you to make uncontrolled conversion possible. An untested conversion can convert raw Foo to Foo<..> (but no more complicated than Foo -> Foo<..>&Bar ).
The spectrum contains only enough tricks to ensure that legacy code can survive typical generation. Your case, of course, is not typical, and tricks do not apply.
source share