Java 10: Will Java 7’s Diamond Inference Work with Local Type Inference?

Yes, var and the diamond operator can be combined together. The compiler will infer the most specific generic type:

var list = new ArrayList<>(); // Infers ArrayList<Object>
var list = new ArrayList<>(List.of(1, 2, 3)); // Infers ArrayList<Integer>

And you can even combine them with an anonymous class:

var list = new ArrayList<>() {};

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)