fork(1) download
  1. import java.lang.reflect.Constructor;
  2. import java.util.List;
  3.  
  4. class TestNested {
  5. Object getLocal() {
  6. class Local {}
  7. return new Local();
  8. }
  9.  
  10. Object getAnonymous() {
  11. return new Object() {};
  12. }
  13.  
  14. class Inner {}
  15.  
  16. Object getInner() {
  17. return new Inner();
  18. }
  19.  
  20. private class PrivateInner {}
  21.  
  22. Object getPrivateInner() {
  23. return new PrivateInner();
  24. }
  25.  
  26. void testAll() {
  27. for(Object o: List.of(getLocal(), getInner(), getPrivateInner(), getAnonymous()))
  28. {
  29. Constructor<?>[] constructors = o.getClass().getDeclaredConstructors();
  30. for(Constructor<?> c: constructors) System.out.println(c);
  31. }
  32. }
  33.  
  34. public static void main(String[] args) throws ClassNotFoundException {
  35. new TestNested().testAll();
  36. }
  37. }
Success #stdin #stdout 0.08s 55920KB
stdin
Standard input is empty
stdout
TestNested$1Local(TestNested)
TestNested$Inner(TestNested)
private TestNested$PrivateInner(TestNested)
TestNested$1(TestNested)