1 Reply Latest reply on Jan 12, 2005 11:12 AM by chiba

    Replace a statement !!

    ericmacau

      Hello,

      How can I replace a statement or expression ?


      For example:


      class Test {
      public static int add(int a, int b) {
      return a+b;
      }
      }


      How can I replace the "return a+b;" with "return _add(a, b);" ?

      And then add another method "public static int _add(int a, int b)".



      Best regards,
      Eric

        • 1. Re: Replace a statement !!
          chiba

          Javassist does not provide direct support for doing that.
          You must manipulate Java bytecode as you do with BCEL.
          Or, you can use insertAfter() so that the result of a+b
          will be discarded and return _add(a, b).