Community
Participate
Working Groups
the following code MUST generate a compiler error or warning, but doesn't: public Set<String>[] test() { Set[] sets = new Set[10]; return sets; }
I think the same problem applies for all array assignments, for example, this code produces no warnings, but gives a run time class cast exception: public class GenericArrayTrouble { public static void main(String[] args) { List<Integer>[] nums = new List[] {Collections.singletonList("Uh oh")}; System.out.println(nums[0].get(0).intValue()); } }
We did not properly check array types. Added support, we now report: Type safety: The expression of type Set[] needs unchecked conversion to conform to Set<String>[]. Added GenericTypeTest#test462.
Second scenario is the same issue indeed. Added GenericTypeTest#test463. Fixed
Tests are actually: test463 & test464.
Verified in I20050214