There can be as many arguments as you like, however the expressions can easily become cluttered and messy, so if you've got a lot of parameters, consider boxing them inside of an new object and passing that object as a single parameter. When you have multiple arguments, you have to wrap them in brackets and give each parameter a name, e.g.;
#forEach((param1, param2, param3, param4, param5, param6, param7) -> doSomething(param5));
This is why Comparator works and why I've used it as so in my earlier post.
Any interface can be used just so long as that interface is a functional interface, aka. an interface that only has one method. For instance, in Lambda, you cannot use MouseListener (or the other mouse/key listener variants), because they have two or more required methods implementations.
If you wanted to implement interfaces via Lambda expressions for one MouseListener function (e.g., #mouseClicked(MouseEvent)), then you could do a work around such as this:
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.List;
public class MouseClicked implements MouseListener {
// Create a list to store our new functional interface type (below)
private final List<Listener> listenerList;
public MouseClicked() {
this.listenerList = new ArrayList<>();
}
@Override
public void mouseClicked(MouseEvent e) {
// Check if list is empty
if (!listenerList.isEmpty()) {
// Iterate through the list and pass the MouseEvent to the functional interfaces
listenerList.forEach(listener -> listener.mouseClicked(e));
}
}
// Delegate methods:
public void addListener(Listener listener) {
listenerList.add(listener);
}
public void removeListener(Listener listener) {
listenerList.remove(listener);
}
// New functional interface:
public static interface Listener {
void mouseClicked(MouseEvent e);
}
/*
* To hold true to the interface "contract", we will have to implement the
* other methods that come packaged with MouseListener. However since we
* don't need to use them/interact with them, we can leave their code bodies
* empty.
*
* Irrelevant methods implements:
*/
@Override
public void mousePressed(MouseEvent e) {
// Ignored.
}
@Override
public void mouseReleased(MouseEvent e) {
// Ignored.
}
@Override
public void mouseEntered(MouseEvent e) {
// Ignored.
}
@Override
public void mouseExited(MouseEvent e) {
// Ignored.
}
}
Then in your script:
public void doSomething() {
// Create new object, which also functions as valid MouseListener
MouseClicked mc = new MouseClicked();
// Add MouseClicked listeners as Lambda expressions
mc.addListener((e) -> System.out.println(e));
// Register the entire listener
getBot().addMouseListener(mc);
}