1 Reply Latest reply on Jun 30, 2007 4:29 PM by ... ...

    How to insrert code directly before/after expression.

    ... ... Newbie

      Hey all, I have a quick question regarding Javassist.

      How do I insert an expression directly before/after an expression?

      For example, I have a HelloWorld class with a log method that prints out the numbers to screen like this:

      1
      2
      3
      5
      6

      Notice number 4 is missing. I want to be able to insert a log("4"); statement between log("3"); and log("5");

      How do I do this?

      HelloWorld.java:

      public class HelloWorld {
       public static void main(String[] args) {
       log("1");
       log("2");
       log("3");
       log("5");
       log("6");
       }
      
       private static void log(Object o) {
       System.out.println(o);
       }
      }