fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.reflect.*;
  5. import java.lang.*;
  6. import java.io.*;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. public static class ThreadA extends Thread {
  12. public void run() {}
  13. }
  14. public static class ThreadB extends Thread {
  15. public void run() {}
  16. }
  17. public static <T extends Thread> T[] makeArray(Class<T> clazz, int n) throws Exception {
  18. T[] res = (T[]) Array.newInstance(clazz, n);
  19. for (int i = 0 ; i < n ; i++) {
  20. res[i] = clazz.newInstance();
  21. res[i].start();
  22. }
  23. return res;
  24. }
  25. public static void main (String[] args) throws java.lang.Exception
  26. {
  27. ThreadA[] aa = makeArray(ThreadA.class, 3);
  28. ThreadB[] bb = makeArray(ThreadB.class, 2);
  29. }
  30. }
Success #stdin #stdout 0.07s 381824KB
stdin
Standard input is empty
stdout
Standard output is empty