简体   繁体   中英

Is lambda expression an improved and essential version of anonymous class in java?

May I say that?

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM