在你的声明1,因为你是指
mylist因为
List<Integer>虽然它仍然是
ArrayList<Integer>,
因此你可以使用在可用的方法
List唯一接口。如果您正在使用跨class.method功能,这是更好的声明。
同样,任何接受方法
List<Integer>都可以接受任何实现类,
List例如
linkedList<Integer>或您的自定义实现类。
您的第二条语句创建并
ArrayList<Integer>仅引用该对象。某些人更倾向于
mylist在方法中本地使用它。

在你的声明1,因为你是指
mylist因为
List<Integer>虽然它仍然是
ArrayList<Integer>,
List唯一接口。如果您正在使用跨class.method功能,这是更好的声明。
同样,任何接受方法
List<Integer>都可以接受任何实现类,
List例如
linkedList<Integer>或您的自定义实现类。
您的第二条语句创建并
ArrayList<Integer>仅引用该对象。某些人更倾向于
mylist在方法中本地使用它。