fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import javax.tools.ToolProvider;
  4. import java.lang.invoke.MethodHandles;
  5.  
  6. /* Name of the class has to be "Main" only if the class is public. */
  7. class Ideone extends Superclass {
  8. public static void main (String[] args) throws java.lang.Exception {
  9. // unqualified invocation of staticMethod() in the context of Ideone
  10. staticMethod();
  11. // qualified invocation using Ideone.staticMethod()
  12. Ideone.staticMethod();
  13. // qualified invocation using Superclass.staticMethod() (the declaring class)
  14. Superclass.staticMethod();
  15. // other example: invoking java.awt.Window.getWindows() via javax.swing.JFrame target
  16. javax.swing.JFrame.getWindows();
  17. }
  18. private Ideone() {}
  19. }
  20. class Superclass {
  21. static boolean disassembled;
  22. static void staticMethod() {
  23. if(!disassembled) {
  24. disassembled = true;
  25. disasm();
  26. }
  27. }
  28. private static void disasm() {
  29. try {
  30. MethodHandles.lookup().unreflect(
  31. Class.forName("com.sun.tools.javap.Main", false, ToolProvider.getSystemToolClassLoader())
  32. .getMethod("main", String[].class))
  33. .asVarargsCollector(String[].class)
  34. .invoke("-c", Ideone.class.getName());
  35. } catch(Throwable t) { t.printStackTrace(); }
  36. }
  37. }
Success #stdin #stdout 1s 72316KB
stdin
Standard input is empty
stdout
Compiled from "Main.java"
class Ideone extends Superclass {
  public static void main(java.lang.String[]) throws java.lang.Exception;
    Code:
       0: invokestatic  #1                  // Method staticMethod:()V
       3: invokestatic  #1                  // Method staticMethod:()V
       6: invokestatic  #2                  // Method Superclass.staticMethod:()V
       9: invokestatic  #3                  // Method javax/swing/JFrame.getWindows:()[Ljava/awt/Window;
      12: pop
      13: return
}