Equivalent for Python's lambda functions in Java?

前端 未结 7 1425
小蘑菇
小蘑菇 2021-02-05 06:41

Can someone please tell me if there is an equivalent for Python\'s lambda functions in Java?

7条回答
  •  醉梦人生
    2021-02-05 06:55

    With the release of Java 8, lambda-expression is now available. And the lambda function in java is actually "more powerful" than the python ones.

    In Python, lambda-expression may only have a single expression for its body, and no return statement is permitted. In Java, you can do something like this: (int a, int b) -> { return a * b; }; and other optional things as well.

    Java 8 also introduces another interface called the Function Interface. You might want to check that out as well.

提交回复
热议问题