Reputation: 2752
May I say that?
Anonymous class looks like OO style while lambda expression makes it functional style.
Upvotes: 2
Views: 331
Reputation: 122449
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.
Upvotes: 5