title: Call all methods within a class
body: <p>I have a class, which has a method calls all of the rest methods within the same class. </p>
  
  <p>One way to do it is by using reflection framework, are there other ways? </p>
  
  <p>[edit]
  Example code added:</p>
  
  <pre>
  <code>
  import java.lang.reflect.InvocationTargetException;
  import java.lang.reflect.Method;
  
  
  public class AClass {
  
      private void aMethod(){
  
      }
  
      private void bMethod(){
  
      }
  
      private void cMethod(){
  
      }
  
      private void dMethod(){
  
      }
  
      //50 more methods. 
  
      //method call the rest
      public void callAll() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException{
          Method[] methods = this.getClass().getMethods();
          for (Method m : methods) {
              if (m.getName().endsWith("Method")) {
                  //do stuff..
              }
          }
      }
  
  }
  </code>
  </pre>
  
  <p>I actually don't have a problem with calling all 4 methods from callAll(), i.e. avoid using reflection. But one of my colleagues pointed out that what if there are 50 methods, are you going to call them one by one? I don't have an answer for that, that's why I am asking the question here. </p>
  
  <p>Thanks,
  Sarah</p>