Is there any way to make this work in Java?
public static void change(List<? extends Object> list, int pos1, int pos2) {
Object obj = list.get(pos1);
list.set(pos1, list.get(pos2));
list.set(pos2, obj);
}
The only way I've successfully avoided warnings and errors is this:
public static <T> T change(List<T> list, int pos1, int pos2) {
T obj = list.get(pos1);
list.set(pos1, list.get(pos2));
list.set(pos2, obj);
return obj;
}
but I don't like to be forced to return a value.