How do I code a function like this one from lambda:
jButton.addActionListener(ae -> callAnyMethod());
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:
I am trying to set a placeholder into the actionPerformed method of my CustomButton ActionListener and call a method like followed :
CustomButton.CustomButtonListener(placeholder method (); )
and the user needs just to create a method and write it inside the bricks ... For example the method named def() :
CustomButton.CustomButtonListener(def());
and def will be passed automatically to the actionPerformed method of my CustomButtonListener and will be fired on button click
Edit:
well that is the code I've came up with so far:
the ActionListener which is stored in my CustomButton class as a method:
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?
}
});
and the code snippet from the button:
CustomButton button = new CustomButton();
button.CustomButtonListener(def());
public void def(){
String a = "lambda!";
System.out.print("a");
}