当前位置:网站首页>[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.parameterTypes
Number of print parameters :
// Number of print parameters println closure.maximumNumberOfParameters
3、 ... 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.maximumNumberOfParameters
Execution results :
[int, class java.lang.String]2
边栏推荐
- User behavior collection platform
- 次小生成树
- Reading and visualization of DICOM, MHD and raw files in medical imaging
- C26451: arithmetic overflow: use the operator * on a 4-byte value, and then convert the result to an 8-byte value. To avoid overflow, cast the value to wide type before calling the operator * (io.2)
- Learning MVVM notes (1)
- [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)
- 函数(基本:参数,返回值)
- PR video clip (project packaging)
- [PCL self study: feature9] global aligned spatial distribution (GASD) descriptor (continuously updated)
- Hypothesis testing -- learning notes of Chapter 8 of probability theory and mathematical statistics
猜你喜欢
首席信息官如何利用业务分析构建业务价值?
2022-2028 global and Chinese video coding and transcoding Market Research Report
User behavior collection platform
函数(基本:参数,返回值)
How to get the first few pieces of data of each group gracefully
直播預告 | 容器服務 ACK 彈性預測最佳實踐
Decryption function calculates "task state and lifecycle management" of asynchronous task capability
函數(易錯)
American 5g open ran suffered another major setback, and its attempt to counter China's 5g technology has failed
Sword finger offer 04 Search in two-dimensional array
随机推荐
Inline built-in function
如何进行「小步重构」?
windows下Redis-cluster集群搭建
Sword finger offer 04 Search in two-dimensional array
Neural networks and deep learning Chapter 6: Circular neural networks reading questions
Leetcode hot topic Hot 100 day 33: "subset"
Key review route of probability theory and mathematical statistics examination
Introduction to RT thread kernel (4) -- clock management
Construction d'un Cluster redis sous Windows
The 22nd Spring Festival Gala, an immersive stage for the yuan universe to shine into reality
Stage experience
Pointer function (basic)
Decryption function calculates "task state and lifecycle management" of asynchronous task capability
English topic assignment (26)
Function template
English topic assignment (27)
Reading and visualization of DICOM, MHD and raw files in medical imaging
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)
蛇形矩阵
介绍汉明距离及计算示例