In the first example, you do not allow Java to capture <T>
in public static <T> List<T> Collections.emptyList()
, since you do not assign it directly to var. Java type inference is very weak and cannot see through a conditional statement. In the second example, you have a simple situation, and T
successfully captured in Integer
.
source share