void (@NotNull List<?> list, int index1, int index2) { Object e1 = list.get(index1); Object e2 = list.get(index2); //noinspection unchecked,rawtypes ((List)list).set(index1, e2); //noinspection unchecked,rawtypes ((List)list).set(index2, e1); }