当前位置:网站首页>[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
边栏推荐
- Introduction to RT thread kernel (5) -- memory management
- How should programmers learn mathematics
- Scope of package class package
- CSDN body auto generate directory
- 官宣!第三届云原生编程挑战赛正式启动!
- This is an age of uncertainty
- Components in protective circuit
- Fonction (sujette aux erreurs)
- After the deployment of web resources, the navigator cannot obtain the solution of mediadevices instance (navigator.mediadevices is undefined)
- Hypothesis testing -- learning notes of Chapter 8 of probability theory and mathematical statistics
猜你喜欢

Special information | finance, accounting, audit - 22.1.23

A survey of automatic speech recognition (ASR) research

2022-2028 global and Chinese virtual data storage Market Research Report

Cookie learning diary 1

JVM 原理和流程简介

Official announcement! The third cloud native programming challenge is officially launched!

The principle of attention mechanism and its application in seq2seq (bahadanau attention)

User behavior collection platform

解密函数计算异步任务能力之「任务的状态及生命周期管理」

Pointer function (basic)
随机推荐
Neural networks and deep learning Chapter 4: feedforward neural networks reading questions
Network layer - forwarding (IP, ARP, DCHP, ICMP, network layer addressing, network address translation)
OWASP top 10 vulnerability Guide (2021)
Mode in BST (binary tree & Notes on question brushing)
Mxnet imports various libcudarts * so、 libcuda*. So not found
JVM 原理和流程简介
2022-2028 global and Chinese video coding and transcoding Market Research Report
Machine learning -- neural network
取余操作是一个哈希函数
CUDA Programming atomic operation atomicadd reports error err:msb3721, return code 1
A survey of automatic speech recognition (ASR) research
Data security -- 14 -- Analysis of privacy protection governance
Interface joint commissioning test script optimization V5.0 (end)
[phantom engine UE] the difference between running and starting, and the analysis of common problems
Web开发人员应该养成的10个编程习惯
[uniapp] system hot update implementation ideas
Function overloading
Download the details and sequence of the original data access from the ENA database in EBI
机器学习 --- 决策树
Advanced length of redis -- deletion strategy, master-slave replication, sentinel mode