Fix Collections.reverse for non-random access lists. Make ArrayList random access.

This commit is contained in:
Alexey Andreev 2018-10-23 17:01:55 +03:00
parent 65c92aab1f
commit 5035c58533
2 changed files with 2 additions and 2 deletions

View File

@ -21,7 +21,7 @@ import org.teavm.classlib.java.lang.*;
import org.teavm.classlib.java.util.function.TUnaryOperator; import org.teavm.classlib.java.util.function.TUnaryOperator;
import org.teavm.interop.Rename; import org.teavm.interop.Rename;
public class TArrayList<E> extends TAbstractList<E> implements TCloneable, TSerializable { public class TArrayList<E> extends TAbstractList<E> implements TCloneable, TSerializable, TRandomAccess {
private E[] array; private E[] array;
private int size; private int size;

View File

@ -224,7 +224,7 @@ public class TCollections extends TObject {
reverse(list, 0, list.size()); reverse(list, 0, list.size());
} else { } else {
TList<Object> randomAccess = new TArrayList<>(list); TList<Object> randomAccess = new TArrayList<>(list);
reverse(list, 0, list.size()); reverse(randomAccess, 0, randomAccess.size());
list.clear(); list.clear();
((TList<Object>) list).addAll(randomAccess); ((TList<Object>) list).addAll(randomAccess);
} }