Question

May I say that?

Anonymous class looks like OO style while lambda expression makes it functional style.

Was it helpful?

Solution

Are you asking about lambdas in Java 8?

A Java 8 lambda is a simplification for a subset of anonymous classes -- namely, anonymous classes that extends a "functional interface", and has exactly one method, does not use this, does not use initializer blocks, and has no fields. (However, this is a very common use case for anonymous classes.)

In other words, any lambda expression can be re-written into an equivalent anonymous class creation expression. But only some (not all) anonymous class creation expressions can be re-written into a lambda expression.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top