// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.util.ArrayList;
import java.util.List;

public class ClassFun {
    public static <T> List<T> gen(int n, Class<T> clz) throws InstantiationException, IllegalAccessException {
        List<T> res = new ArrayList<T>();
        for(int i = 0; i < n; i++) {
            res.add(clz.newInstance());
        }
        return res;
    }
    public static void main(String[] args) throws Exception {
        List<A> alst = gen(3, A.class);
        for(A a : alst) {
            System.out.println(a);
        }
        List<B> blst = gen(3, B.class);
        for(B b : blst) {
            System.out.println(b);
        }
    }
}

class A {
    @Override
    public String toString() {
        return "I am an A";
    }
}

class B {
    @Override
    public String toString() {
        return "I am an B";
    }
}
