当前位置:网站首页>[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
边栏推荐
- Download the details and sequence of the original data access from the ENA database in EBI
- 包 类 包的作用域
- Solution of circular dependency
- Function (error prone)
- Group counting notes (1) - check code, original complement multiplication and division calculation, floating point calculation
- 官宣!第三届云原生编程挑战赛正式启动!
- 2022-2028 global and Chinese virtual data storage Market Research Report
- 这是一个不确定的时代
- [PCL self study: feature9] global aligned spatial distribution (GASD) descriptor (continuously updated)
- You Li takes you to talk about C language 7 (define constants and macros)
猜你喜欢

CSDN body auto generate directory

函数(易错)

直播预告 | 容器服务 ACK 弹性预测最佳实践

10 programming habits that web developers should develop

Decryption function calculates "task state and lifecycle management" of asynchronous task capability
![[illusory engine UE] method to realize close-range rotation of operating objects under fuzzy background and pit recording](/img/11/b55f85ef9e1f22254218cb9083b823.png)
[illusory engine UE] method to realize close-range rotation of operating objects under fuzzy background and pit recording

介绍汉明距离及计算示例

SPI read / write flash principle + complete code

A survey of automatic speech recognition (ASR) research

Minor spanning tree
随机推荐
[phantom engine UE] the difference between running and starting, and the analysis of common problems
Solution of circular dependency
Private collection project practice sharing [Yugong series] February 2022 U3D full stack class 006 unity toolbar
Burpsuite grabs app packets
[illusory engine UE] method to realize close-range rotation of operating objects under fuzzy background and pit recording
Wan broadband access technology V EPON Technology
[Chongqing Guangdong education] National Open University 2047t commercial bank operation and management reference test in autumn 2018
Mode in BST (binary tree & Notes on question brushing)
Setting up redis cluster cluster under Windows
Flink集群配置
CSDN body auto generate directory
Machine learning decision tree
[Business Research Report] top ten trends of science and technology and it in 2022 - with download link
蛇形矩阵
Hexadecimal to decimal
Official announcement! The third cloud native programming challenge is officially launched!
CSDN正文自动生成目录
美国5G Open RAN再遭重大挫败,抗衡中国5G技术的图谋已告失败
MySQL in-depth learning - index creation and deletion, index design principles, index failure scenarios, query optimization, index push down ICP
Raki's notes on reading paper: code and named entity recognition in stackoverflow