当前位置:网站首页>[groovy] closure (Introduction to closure class closure | closure parametertypes and maximumnumberofparameters member usage)
[groovy] closure (Introduction to closure class closure | closure parametertypes and maximumnumberofparameters member usage)
2022-07-05 04:40:00 【Programmer community】
List of articles
- One 、 Closure class Closure brief introduction
- Two 、 Closure parameterTypes and maximumNumberOfParameters Member usage
- 3、 ... and 、 Complete code example
One 、 Closure class Closure brief introduction
Closure is Closure object , Closure There are many members in the class , And encapsulated functions , Here is Closure Class inheritance structure ;
/** * stay Groovy Represents any closure object . * <p> * Groovy Allow closure instances to be called in a short form . for example : * <pre> * def a = 1 * def c = { a } * assert c() == 1 * </pre> * In order to be able to use closures in your own subclasses in this way , * You need to provide a with any signature you want doCall Method . * This ensures that the {@link#getMaximumNumberOfParameters()} * and {@link#getParameterTypes()} stay * It works without any extra code . * If not provided doCall Method , You must use closures in long form , Such as * <pre> * def a = 1 * def c = {a} * assert c.call() == 1 * </pre> * * @author <a href="mailto:[email protected]">James Strachan</a> * @author <a href="mailto:[email protected]">John Wilson</a> * @author <a href="mailto:[email protected]">Jochen Theodorou</a> * @author Graeme Rocher * @author Paul King */public abstract class Closure<V> extends GroovyObjectSupport implements Cloneable, Runnable, GroovyCallable<V>, Serializable {
}Two 、 Closure parameterTypes and maximumNumberOfParameters Member usage
stay Closure class Closure in , There are the following
2
2
2 Members :
protected Class[] parameterTypes; protected int maximumNumberOfParameters;Class[] parameterTypes Is a parameter type , int maximumNumberOfParameters Is the maximum number of parameters required , When invoking closures , When you don't know what type of parameters to pass to a closure , Do not know how many parameters are passed , You can use Above
2
2
2 Members ;
The following code , Define a closure :
// Define closure // The closure receives 2 Parameters def closure = {
int a, String b ->}If you use closure Closure time , I don't know what type of parameters the closure receives , And the number of parameters , have access to println Print closure parameters ;
Print parameter type : Above
2
2
2 Parameters , The printed result is [int, class java.lang.String] ;
// Print parameter type println closure.parameterTypesNumber of print parameters :
// Number of print parameters println closure.maximumNumberOfParameters3、 ... and 、 Complete code example
Complete code example :
// Define closure // The closure receives 2 Parameters def closure = {
int a, String b ->}// Print parameter type println closure.parameterTypes// Number of print parameters println closure.maximumNumberOfParametersExecution results :
[int, class java.lang.String]2
边栏推荐
- [popular science] basic knowledge of thermal design: heat dissipation analysis of 5g optical devices
- NetSetMan pro (IP fast switching tool) official Chinese version v5.1.0 | computer IP switching software download
- Rk3399 platform development series explanation (network debugging) 7.29 summary of network performance tools
- PHP reads the INI file and writes the modified content
- Observable time series data downsampling practice in Prometheus
- 首席信息官如何利用业务分析构建业务价值?
- How should programmers learn mathematics
- 自动语音识别(ASR)研究综述
- flutter 对象和列表
- 函數(易錯)
猜你喜欢

指针函数(基础)

MacBook installation postgresql+postgis

Minor spanning tree

Solution of circular dependency

Advanced length of redis -- deletion strategy, master-slave replication, sentinel mode
![[moteur illusoire UE] il ne faut que six étapes pour réaliser le déploiement du flux de pixels ue5 et éviter les détours! (4.26 et 4.27 principes similaires)](/img/eb/a93630aff7545c6c3b71dcc9f5aa61.png)
[moteur illusoire UE] il ne faut que six étapes pour réaliser le déploiement du flux de pixels ue5 et éviter les détours! (4.26 et 4.27 principes similaires)

NetSetMan pro (IP fast switching tool) official Chinese version v5.1.0 | computer IP switching software download

What are the building energy-saving software

2022-2028 global and Chinese FPGA prototype system Market Research Report

防护电路中的元器件
随机推荐
Data security -- 14 -- Analysis of privacy protection governance
Qt蓝牙:搜索蓝牙设备的类——QBluetoothDeviceDiscoveryAgent
[goweb development] Introduction to authentication modes based on cookies, sessions and JWT tokens
WeNet:面向工业落地的E2E语音识别工具
PR video clip (project packaging)
机器学习 --- 神经网络
Raki's notes on reading paper: soft gazetteers for low resource named entity recognition
Decimal to hexadecimal
The principle of attention mechanism and its application in seq2seq (bahadanau attention)
Learning MVVM notes (1)
2022-2028 global and Chinese FPGA prototype system Market Research Report
Leetcode 222 number of nodes of complete binary tree
介绍汉明距离及计算示例
[phantom engine UE] package error appears! Solutions to findpin errors
American 5g open ran suffered another major setback, and its attempt to counter China's 5g technology has failed
MySQL in-depth learning - index creation and deletion, index design principles, index failure scenarios, query optimization, index push down ICP
Uncover the seven quirky brain circuits necessary for technology leaders
How should programmers learn mathematics
Introduction to RT thread kernel (5) -- memory management
直播預告 | 容器服務 ACK 彈性預測最佳實踐