the puzzle of Collections.emptyList()
collections, generics, java
Solution
Try this:
List<Integer> i = j > 0 ? Collections.<Integer>emptyList() : new ArrayList<Integer>();
Problem
``` int j = 0; List<Integer> i = j > 0 ? Collections.emptyList() : new ArrayList<Integer>(); // compiler error:cannot convert from List<capture#1-of ? extends Object> to List<Integer> ``` while, ``` List<Integer> li = Collections.emptyList(); // it works ``` Although i know the type erasure, i do not the reason of compiling failed! Help, thx!