introduction to functional programming
Published:
Java basics – introduction to functional programming
Introduction to functional programming
Thought
Object-oriented thinking: find an object, call the method of the object, and complete the task.
Functional programming idea: As long as you can get results, focus on results instead of process.
Lambda expression
new Thread(()->{
//do something
}).start();
- No parameters
- No return value
- Code block: the specific execution steps of the program
Format
There are three parts
- Some parameters: leave them blank if there are no parameters, write parameters if there are parameters, multiple parameters are separated by commas
- An arrow: the meaning of passing, passing parameters to the method body
- A piece of code: rewrite the method body of the interface abstract method
(Parameter list)->(some rewrite method code);
Lambda omitted format
Lambda expressions can be deduced and omitted, and everything that can be deduced can be omitted
What can be omitted:
- Parameter list: The data type of the parameter list in parentheses can be omitted.
- Parameter list: there is only one parameter in brackets, type and () can be omitted
- Some codes: If there is only one line of code in (), no matter whether there is a return value or not, {}, return, semicolon can be omitted (if it is omitted, it must be omitted together)