当前位置:网站首页>[groovy] closure (closure call | closure default parameter it | code example)
[groovy] closure (closure call | closure default parameter it | code example)
2022-07-05 04:41:00 【Programmer community】
One 、 Call closure
perform Closure Variable Of call() Method , You can call the closure ;
// Define closure variables def closure = {
println "Hello Closure!" } // Call closure closure.call()
Execute the above code , Print Hello Closure!
;
direct stay Closure After a variable , Write a bracket , You can also call closures ;
// Define closure variables def closure = {
println "Hello Closure!" } // Call closure closure()
Execute the above code , Print Hello Closure!
;
Two 、 Closure default parameters it
Closure Closure Default OK Receive a default parameter , The parameter variable name is it ,
- If No parameter passed in , Then it for null ,
- If Pass in the parameter , The it Variable is the parameter value that should be passed in ;
stay closure() Invocation time , Pass in a parameter , It will be automatically assigned to it Variable ;
// Define closure variables def closure = {
println it } // Call closure , And pass in a default parameter closure("Hello")
The above code will print Hello
;
3、 ... and 、 Code example
Code example :
class Test {
static void main(args) {
// Define closure variables def closure = {
println "Hello Closure!" } // I. Print closure type // Print closure variable types println closure.getClass() // II. Call closure // Call closure 1 closure.call() // Call closure 2 closure() // III. Closure default parameters // Define closure variables def closure1 = {
println it } // Call closure closure1.call("Hello") // Call closure , And pass in a default parameter closure1("Closure") }}
Execution results :
class Test$_main_closure1Hello Closure!Hello Closure!HelloClosure
边栏推荐
- Uncover the seven quirky brain circuits necessary for technology leaders
- Discussion on the dimension of confrontation subspace
- Stage experience
- Mode in BST (binary tree & Notes on question brushing)
- 解密函数计算异步任务能力之「任务的状态及生命周期管理」
- 线上故障突突突?如何紧急诊断、排查与恢复
- Download the details and sequence of the original data access from the ENA database in EBI
- Wan broadband access technology V EPON Technology
- American 5g open ran suffered another major setback, and its attempt to counter China's 5g technology has failed
- 直播预告 | 容器服务 ACK 弹性预测最佳实践
猜你喜欢
MacBook installation postgresql+postgis
The 22nd Spring Festival Gala, an immersive stage for the yuan universe to shine into reality
About the prompt loading after appscan is opened: guilogic, it keeps loading and gets stuck. My personal solution. (it may be the first solution available in the whole network at present)
49 pictures and 26 questions explain in detail what is WiFi?
[uniapp] system hot update implementation ideas
Power management bus (pmbus)
Moco is not suitable for target detection? MsrA proposes object level comparative learning target detection pre training method SOCO! Performance SOTA! (NeurIPS 2021)...
mxnet导入报各种libcudart*.so、 libcuda*.so找不到
Hypothesis testing -- learning notes of Chapter 8 of probability theory and mathematical statistics
A solution to the problem that variables cannot change dynamically when debugging in keil5
随机推荐
Function template
[uniapp] system hot update implementation ideas
指针函数(基础)
How should programmers learn mathematics
[popular science] basic knowledge of thermal design: heat dissipation analysis of 5g optical devices
取余操作是一个哈希函数
Moco is not suitable for target detection? MsrA proposes object level comparative learning target detection pre training method SOCO! Performance SOTA! (NeurIPS 2021)...
Data security -- 14 -- Analysis of privacy protection governance
Construction d'un Cluster redis sous Windows
Setting up redis cluster cluster under Windows
Is there a sudden failure on the line? How to make emergency diagnosis, troubleshooting and recovery
MySQL in-depth learning - index creation and deletion, index design principles, index failure scenarios, query optimization, index push down ICP
Network security - record web vulnerability fixes
托管式服务网络:云原生时代的应用体系架构进化
Private collection project practice sharing [Yugong series] February 2022 U3D full stack class 006 unity toolbar
Download the details and sequence of the original data access from the ENA database in EBI
官宣!第三届云原生编程挑战赛正式启动!
3 minutes learn to create Google account and email detailed tutorial!
QT Bluetooth: a class for searching Bluetooth devices -- qbluetooth devicediscoveryagent
Decryption function calculates "task state and lifecycle management" of asynchronous task capability