有没有办法覆盖Java方法,唯一改变的是ArrayList?
例如:
public void quickSortMethod(ArrayList<Integer> comparison, int start, int end)
{}
public void quickSortMethod(ArrayList<Double> comparison, int start, int end)
{}
Run Code Online (Sandbox Code Playgroud)
这目前给我以下错误:
Method quickSortMethod(ArrayList<Integer>, int, int) has the same erasure quickSortMethod(ArrayList<E>, int, int) as another method in type QuickSort
Run Code Online (Sandbox Code Playgroud)
顺便说一下,我正在使用我在ArrayLists中创建的其他对象作为参数
ArrayList<MyObject>...
Run Code Online (Sandbox Code Playgroud)
Rob*_*ani 10
在这种情况下,您可以尝试使该方法本身通用,并使用该类型作为ArrayList类型...
public <T> void quickSortMethod(ArrayList<T> comparison, int start, int end)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1244 次 |
| 最近记录: |