0 Replies Latest reply on Jan 16, 2006 5:30 PM by Klemens Schrage

    Merge variuos Methods

    Klemens Schrage Newbie

      Hi!

      The problem is that I can`t merge the bytecodes of two or more methods into a single one. A combination of these methods in a single methode is striven. (With additional "connector"-code between the Method blocks).

      Here's my code-sample:

      (Classes A and B are merged within Class C)

      public class A {
      
       public int doIt() {
       int a = 5;
       a = a*5;
      
       return a;
       }
      }
      
      public class B {
      
       public int doIt() {
       int a = 10;
       a = a / 10;
      
       return a;
       }
      }
      
      public class C {
       private static final int ID_A = 1;
       private static final int ID_B = 2;
      
       private int id;
      
       public C (int id) {
       this.id = id;
       }
      
       public int doIt() {
       switch (id) {
       case ID_A:
       int a = 5;
       a = a*5;
      
       return a;
       case ID_B:
       int a = 10;
       a = a / 10;
      
       return a;
       }
      
       return -1;
       }
      
      }

      I could use auxiliary methods and call them within the "case" but is there another way to archieve the desired functionality?