- 将代码中的ArrayList
原始代码示例:
ArrayList
修改后的代码示例:
ArrayList list = new ArrayList<>();
list.add(new UserLocation("John", 123.123, 45.45));
list.add(new UserLocation("Ali", 98.12, -122.45));
list.add(new UserLocation("Alex", -12.34, 23.45));
- 使用泛型边界
原始代码示例:
public void processList(ArrayList list) {
// do something with the list
}
调用该方法的代码示例:
ArrayList
修改后的代码示例:
public void processList(ArrayList extends UserLocation> list) {
// do something with the list
}
调用该方法的代码示例:
ArrayList list = new ArrayList<>();
list.add(new UserLocation("John", 123.123, 45.45));
list.add(new UserLocation("Ali", 98.12, -122.45));
list.add(new UserLocation("Alex", -12.34, 23.45));
processList(list);