I have to be honest, so far I have not paid too much attention to the Java 8 features. Mainly because my clients have been slow to adapt to 1.8 JVM. There just has not been a compelling reason for them to do so. Thus, they’re content running on Java 1.6 or Java 1.7. But with the release of version 4 of the Spring Framework, I suspect this is going to change. There are features in Spring 4 we will want to use. So, now we actually have a reason to move to Java 1.8.
Lambdas are one of the more interesting features of Java 1.8. I first heard about Lambdas from my friend Maurice Naftalin. He has a web site dedicated to Lambdas here. So, what is a Lambda? In a nutshell, as Maurice explains, its a function. My initial reaction was meh, Groovy has had this feature for years. Functionally, Java Lambdas are roughly the same thing as Groovy closures. (Maurice may cringe at this statement…) They’re pretty darn close, but as usual the Groovy syntax is more concise.
With Spring 4 out on the market now, it is time to get smart about Java Lambdas. You’re going to see them used more and more. One great example of Java Lambdas in action is with the Spring JdbcTemplate here. It gives you a slightly more concise and cleaner syntax than using anonymous inner classes. (I’ve never been a big fan of anonymous inner classes – they seem like a code smell to me)
Java Lambdas are a nice improvement to the Java language. Its good to see Spring starting to incorporate them into Spring 4. This is just the first release. I’m sure we will see a lot more of Lambdas in the future!