title: Create a dynamic function call in java
body: <p>I need a way to write a command call that will be executed in compiled code. However, the command will be store in a database as a String because it's configurable by the user. Each command would match a class but there could be multiple commands that need to be executed with input parameters.</p>
  
  <p>How is the best way of handling this?</p>
  
  <p>Example Class that would be called:</p>
  
  <pre><code>public class CreateUser {
     protected User user; 
  
     public static void create(User user){
        CreateUser cu = new CreateUser(user);
        cu.newUserFunction();
     }
  
     public CreateUser(User user){
        this.user = user;
     }
  
     public void newUserFunction(){
        doSomething();
     }
  }
  </code></pre>
  
  <p>Example Method that would call the command:</p>
  
  <pre><code>public void createUser(User user){
    dclCommand.createUser(user.getUsername(), user.getPassword());
  
    // Get special commands to run after user is created
    List&lt;Command&gt; cmds = this.dbRepository.findCommand(database, Method.CREATE_USER);
    for(Command cmd : cmds){
       // Here is where the cmd will be executed with input parameters
       // In example the command executed would be 'org.example.CreateUser.create(user)'
    }
  } 
  </code></pre>
  
  <p>The call to 'org.example.CreateUser.create(user)' will be stored in a database and I need to be able to run it from a function that will get it out of the database and call it adding the parameter User.</p>