fork(2) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. interface IFace<T> {}
  11. static class Something implements IFace<String> {}
  12.  
  13. static class Whatever {
  14. protected <C extends IFace<?>> Class<C> getClazz() {
  15. return (Class<C>) (Class) IFace.class;
  16. }
  17. }
  18.  
  19. public static void main (String[] args) throws java.lang.Exception
  20. {
  21. Class<Something> clazz = new Whatever().getClazz();
  22. try {
  23. Something sth = clazz.newInstance();
  24. } catch (Exception e) {
  25. e.printStackTrace(System.out);
  26. }
  27. }
  28. }
Success #stdin #stdout 0.04s 4386816KB
stdin
Standard input is empty
stdout
java.lang.InstantiationException: Ideone$IFace
	at java.lang.Class.newInstance(Class.java:427)
	at Ideone.main(Main.java:23)
Caused by: java.lang.NoSuchMethodException: Ideone$IFace.<init>()
	at java.lang.Class.getConstructor0(Class.java:3082)
	at java.lang.Class.newInstance(Class.java:412)
	... 1 more