Wednesday, February 11, 2015

Java 8 lambda example 1

I started some new development work today and decided it is time to start moving to JDK 8.  Looks like existing code compiled as JDK 7 source tends to run ok under JDK 8 already. With some of the new functionality I needed though, it seemed reasonable to start working with actual JDK 8 specifics though.

This is a sample demonstrating some JDK 8 features I am using.


Here is the test class demonstrating some JDK 8 functionality.  

and here is the resulting output:
The regular expression from SampleEnum.flatList() is: (Item1|Item2|Item3|Item4).*
[Item1] matches
[Item3] matches
[Item4 with extra] matches

I am far from an expert on functional programming but I do like to dabble in them.  I do think there are times where the new JDK 8 functionality will promote smaller (and hopefully more maintainable) code.  A famous quote seems appropriate here - "With great power comes great responsibility".  I also foresee some real ugly code being spawned into existence.  I will try to take the good with the bad and try to use the tools at hand to make things better rather than worse. 

No comments:

Post a Comment