title: How to create a lambda-like pattern in ActionListener
body: <p>How do I code a function like this one from lambda:</p>
  
  <pre><code>jButton.addActionListener(ae -&gt; callAnyMethod());
  </code></pre>
  
  <p>because I am creating a library and would like to implement such a pattern on my own.
  Before Java 8 and lambda was released how would someone made such a pattern ? like what I am trying to approach is following:</p>
  
  <p>I am trying to set a placeholder into the actionPerformed method of my CustomButton ActionListener and call a method like followed :</p>
  
  <pre><code>CustomButton.CustomButtonListener(placeholder method (); ) 
  </code></pre>
  
  <p>and the user needs just to create a method and write it inside the bricks ... For example the method named def() : </p>
  
  <pre><code>CustomButton.CustomButtonListener(def());
  </code></pre>
  
  <p>and def will be passed automatically to the actionPerformed method of my CustomButtonListener and will be fired on button click </p>
  
  <p>Edit:</p>
  
  <p>well that is the code I've came up with so far:</p>
  
  <p>the ActionListener which is stored in my CustomButton class as a method:</p>
  
  <pre><code>public void CustomButtonListener(Object object){
  
          addActionListener(new ActionListener(){
  
  @Override
          public void actionPerformed(ActionEvent e) {
  
  
  
            // how to call the method stored in the Object "object" here? and actually run it?
  
  
  
              }
      });
  </code></pre>
  
  <p>and the code snippet from the button:</p>
  
  <pre><code>CustomButton button = new CustomButton();
  
  button.CustomButtonListener(def());
  
  
  
  
  
  public void def(){
  
      String a = "lambda!";
  
              System.out.print("a");
  
  
  
  }
  </code></pre>