First, all my action listeners call a private method in my class. They are in the initComponents
method that is not static, and so are the private method called by the action listeners.
The project was on Java 1.5 and moved to Java 1.8. SonarLint didn't like those statements :
someButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
doSomeAction(evt);
}
});
At first, SonarLint propose to change those assignment using lambdas (Squid:S1604).
I changed those with:
someButton.addActionListener(e -> doSomeAction(e));
Then the strange Squid:S1612 occured: it propose to use method references instead. Here is what I did:
someButton.addActionListener(ClassName::doSomeAction);
Then Eclipse Oxygen said that this is an error and won't compile The error message is:
Cannot make a static reference to the non-static method doSomeAction(ActionEvent) from the type ClassName
So the question is: can I really use method reference or should I just stick with lambda?