Return Lambda from Method in Java 8?

后端 未结 5 1469
轮回少年
轮回少年 2021-01-31 03:01

I have just begun to use Java 8 and I am wondering if there is a way to write a method that returns a Function?

Right now I have method like below:

5条回答
  •  后悔当初
    2021-01-31 03:14

    Get rid of your return statement inside of your function definition:

    Function getMyFunction() {
        return (it) -> "Hello, world: " + it;
    }
    

提交回复
热议问题