当前位置:网站首页>[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
边栏推荐
- [illusory engine UE] method to realize close-range rotation of operating objects under fuzzy background and pit recording
- PHP reads the INI file and writes the modified content
- English topic assignment (27)
- flutter 对象和列表
- 2022-2028 global and Chinese equipment as a Service Market Research Report
- Matplotlib draws three-dimensional scatter and surface graphs
- Burpsuite grabs app packets
- CSDN body auto generate directory
- Fonction (sujette aux erreurs)
- 防护电路中的元器件
猜你喜欢

计组笔记(1)——校验码、原补码乘除计算、浮点数计算

Thematic information | carbon, carbon neutrality, low carbon, carbon emissions - 22.1.9

What are the building energy-saving software

Discussion on the dimension of confrontation subspace

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

Managed service network: application architecture evolution in the cloud native Era
![[finebi] the process of making custom maps using finebi](/img/3a/d638dbac6a26c37087ec9550c35e63.png)
[finebi] the process of making custom maps using finebi
![[uniapp] system hot update implementation ideas](/img/1e/77ee9d9f0e08fa2a7734a54e0c5020.png)
[uniapp] system hot update implementation ideas
![[phantom engine UE] realize the animation production of mapping tripod deployment](/img/89/351641c3da7e2acdbf389bc298b75e.png)
[phantom engine UE] realize the animation production of mapping tripod deployment

解密函数计算异步任务能力之「任务的状态及生命周期管理」
随机推荐
How to force activerecord to reload a class- How do I force ActiveRecord to reload a class?
WeNet:面向工业落地的E2E语音识别工具
Convert Boolean to integer value PHP - Convert Boolean to integer value PHP
level17
PHP reads the INI file and writes the modified content
Minor spanning tree
Interface joint commissioning test script optimization V5.0 (end)
Introduction to RT thread kernel (4) -- clock management
PHP读取ini文件并修改内容写入
English topic assignment (27)
Discussion on the dimension of confrontation subspace
Key review route of probability theory and mathematical statistics examination
Aperçu en direct | Services de conteneurs ACK flexible Prediction Best Practices
QT Bluetooth: a class for searching Bluetooth devices -- qbluetooth devicediscoveryagent
Stage experience
Is there a sudden failure on the line? How to make emergency diagnosis, troubleshooting and recovery
[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)
Variable category (automatic, static, register, external)
SQL set operation
美国5G Open RAN再遭重大挫败,抗衡中国5G技术的图谋已告失败