Odd method call in java using a dot operator to access a generic list

You more often think of classes as being generic, but methods can be generic too. A common example is Arrays.asList.

Most of the time, you don’t have to use the syntax with angle brackets <...>, even when you’re invoking a generic method, because this is the one place in which the Java compiler is actually capable of doing basic type inference in some circumstances. For example, the snippet given in the Arrays.asList documentation omits the type:

List<String> stooges = Arrays.asList("Larry", "Moe", "Curly");

But it’s equivalent to this version in which the generic type is given explicitly:

List<String> stooges = Arrays.<String>asList("Larry", "Moe", "Curly");

Leave a Comment