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<>() {};
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…