2 Replies Latest reply on Feb 24, 2005 10:05 AM by javasvada

    Constructor modification?

    javasvada

      I am modifying an existing constructor

      CtConstructor constructor=cc.getConstructors()[0];
      constructor.setBody("System.out.println(\"hello1\"); System.out.println(\"hello2\"); ");
      


      But for some reason, only the first statement is added (I double checked by decompiling the class), and when running only Hello1 is printed.

      Anyone know what the problem might be, and how to fix this?

      Thanks!

        • 1. Re: Constructor modification?
          chiba

          Ah... the statements must be surrounded by {}.
          So

          setBody("{ System.out.println(...); ...println(...); }");

          is correct. I agree this spec. should be changed. :-(

          • 2. Re: Constructor modification?
            javasvada

             

            "chiba" wrote:
            Ah... the statements must be surrounded by {}.
            So

            setBody("{ System.out.println(...); ...println(...); }");

            is correct. I agree this spec. should be changed. :-(


            Ah, I see, it works now. Thanks for the reply :)