Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
10.0
-
None
-
None
-
Linux Mint 19, JDK8
Description
Following class file (JDK 8):
public class TestApp { private JButton btnTest = new JButton("Test"); public void testMethod() { btnTest.addActionListener((e) -> doSomething(e)); btnTest.addActionListener(TestApp::doSomething); } private void doSomething(ActionEvent e) { System.out.println("Yeah!"); } }
Both lines
btnTest.addActionListener((e) -> doSomething(e)); btnTest.addActionListener(TestApp::doSomething);
are valid Java 8 compatible lines (first line as lambda reference, second line as method reference). The editor pane don't marks one of these lines as an error (which is correct for me). But the Java file (in the project tree and the editor tab) is marked with an error icon. The "Action Items" view will be shown following error message:
incompatible types: invalid method reference unexpected instance method doSomething(java.awt.event.ActionEvent) found in unbound lookup
Reason of this error message is the second line with the method reference. I think the error in this place is not not correct. Here I would expect no error.
Workaround: Use lambda expressions instead of method refernce