Lambdas in the classical Operation enum example

前端 未结 4 2158
长情又很酷
长情又很酷 2020-12-01 05:16

As many of you may know, there is a classical example of the Operation enum (using Java 8 standard interface now though), that is the following:



        
4条回答
  •  心在旅途
    2020-12-01 05:56

    I'm surprised no one mentioned this, but the lambda approach can get hairy when implementing multiple methods. Passing a bunch of nameless lambdas into a constructor will be more concise, but not necessarily more readable.

    Also, the benefit of using a lambda decreases as the function grows in size. If your lambda is more than several lines long, an override might be just as easy to read, if not easier.

提交回复
热议问题