-
Enhancement
-
Resolution: Won't Fix
-
P4
-
None
-
14
A DESCRIPTION OF THE PROBLEM :
There exists in the Collections class a method called "nCopies". Optimize this method to return Collections.emptyList() if n equals 0 to avoid instantiating an empty CopiesList object.
public static <T> List<T> nCopies(int n, T o) {
if (n < 0)
throw new IllegalArgumentException("List length = " + n);
return new CopiesList<>(n, o);
}
There exists in the Collections class a method called "nCopies". Optimize this method to return Collections.emptyList() if n equals 0 to avoid instantiating an empty CopiesList object.
public static <T> List<T> nCopies(int n, T o) {
if (n < 0)
throw new IllegalArgumentException("List length = " + n);
return new CopiesList<>(n, o);
}