Kenneth Fogel created NETBEANS-4761:
---------------------------------------

             Summary: Conversion of loops to functional notation in this 
example fails
                 Key: NETBEANS-4761
                 URL: https://issues.apache.org/jira/browse/NETBEANS-4761
             Project: NetBeans
          Issue Type: Bug
    Affects Versions: 12.0
         Environment: Windows 10, Java 14, NB 12.0
            Reporter: Kenneth Fogel
             Fix For: 12.0


When NB recommends converting certain loops into functional notation things go 
very wrong.

This is the original code:
        for (String emailAddress : mailBean.getToField()) {
            email.to(emailAddress);
        }

mailBean.getToField() is returning an ArrayList of Strings.

This is the conversion to functional notation done by hand:
        mailBean.getToField().forEach(emailAddress -> {
            email.to(emailAddress);
        });
This code does work and my program correctly adds email address to the 'to' 
field. I am using the Jodd email library.

 NB wants to convert the first loop to functional notation. This is what it 
produces:
        mailBean.getToField()) {
            email.to(em.forEach(emailAddress ->ilAddress);
        }
   );     

As you can see the conversion has intertwined code like a tangled earphone 
cable.

Given a simpler problem such as:
        for(String stuff : al) {
            System.out.println(stuff);
        }
where al is an ArrayList of 100 Strings NB correctly converts this to
 al.forEach(stuff -> {
            System.out.println(stuff);
        });

Thinking that it could be the method call to access the ArrayList I rewrote the 
code as:
        ArrayList<String> al = mailBean.getToField();

        for (String emailAddress : al) {
            email.to(emailAddress);
        }

Now when I let NB convert the loop to functional notation I received:
        al.fotring emailAddress :->{
            email.to(emailAddress);
        }
   );     
 
What am I doing wrong?
 







--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org
For additional commands, e-mail: commits-h...@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to