Question

May I say that?

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

Était-ce utile?

La 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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top