Whenever you create a generic method with a signature that promises returns all the wishes of the caller, you ask for troubles. You should receive an βunverifiedβ warning from the compiler, which basically means: an unexpected ClassCastException may occur.
You expect the compiler to conclude
List<CB> bl1 = Arrays.asList(YourClass.<CA,CB>convert(a));
whereas the compiler actually deduced
List<CB> bl1 = Arrays.asList(YourClass.<CA,CB[]>convert(a));
as far as I know, because he prefers method calls that don't require varargs packaging (which is compatible with pre-varargs code).
This fails because your convert method does not return the expected array type.
Holger
source share