//: typeinfo/FilledList.java
package typeinfo; /* Added by Eclipse.py */
import java.util.*;
class CountedInteger {
private static long counter;
private final long id = counter++;
public String toString() { return Long.toString(id); }
}
public class FilledList {
private Class type;
public FilledList(Class type) { this.type = type; }
public List create(int nElements) {
List result = new ArrayList();
try {
for(int i = 0; i < nElements; i++)
result.add(type.newInstance());
} catch(Exception e) {
throw new RuntimeException(e);
}
return result;
}
public static void main(String[] args) {
FilledList fl =
new FilledList(CountedInteger.class);
System.out.println(fl.create(15));
}
} /* Output:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
*///:~