Uploaded image for project: 'NetBeans'
  1. NetBeans
  2. NETBEANS-1982

Java class marks with error, but Java class don't contains any error

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 10.0
    • None
    • cnd - Editor
    • 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

       

       

       

      Attachments

        1. TestApp.java
          0.4 kB
          Steffen Ewert

        Activity

          People

            Unassigned Unassigned
            stewert72 Steffen Ewert
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: