I have been in the software development industry since 2010, working on enterprise product development using ADF. I am usually keen on learning about software design and emerging technologies. You can find me hanging around in the JavaRanch Forums where I am one of the moderators. Apart from Java, I am fascinated by the ease of use and simplicity of Ruby and Rails. Mohamed is a DZone MVB and is not an employee of DZone and has posted 53 posts at DZone. You can read more from them at their website. View Full User Profile

A Look at Netbeans Support for Upcoming Language Enhancements in Java 8

03.22.2013
| 1865 views |
  • submit to reddit

While I was working on the samples for this post using the Nebeans nightly builds with support for Lambda Expressions downloaded from here. I found that the IDE gave good suggestions for converting the code to use the Java 8 support as and where possible. For example I had a small piece of code:

List<Person> olderThan30OldWay = new ArrayList<>();
for ( Person p : personList){
  if ( p.age >= 30){
    olderThan30OldWay.add(p);
  }
}
System.out.println(olderThan30OldWay);

and the IDE showed an yellow line under the for and provided a hint as shown in the screenshot below:
Functional_Hint
and using the hint resulted in the following code being added in place of the above code:

List<Person> olderThan30OldWay = new ArrayList<>();
personList.stream().filter((p) -> ( p.age >= 30)).forEach((p) -> {
  olderThan30OldWay.add(p);
});
System.out.println(olderThan30OldWay);

This is going to be really useful for people to identify where the code can be replaced by Lambda Expression. A more detailed intent of experimenting with the above sample can be found in my previous post here.


 

Published at DZone with permission of Mohamed Sanaulla, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)