当前位置:网站首页>[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
边栏推荐
- [crampon programming] lintcode decoding Encyclopedia - 1100 strange printer
- Moco is not suitable for target detection? MsrA proposes object level comparative learning target detection pre training method SOCO! Performance SOTA! (NeurIPS 2021)...
- Hypothesis testing -- learning notes of Chapter 8 of probability theory and mathematical statistics
- Debug insights
- 2022-2028 global and Chinese virtual data storage Market Research Report
- Solution of circular dependency
- 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)
- Neural networks and deep learning Chapter 5: convolutional neural networks reading questions
- OWASP top 10 vulnerability Guide (2021)
- Variable category (automatic, static, register, external)
猜你喜欢

假设检验——《概率论与数理统计》第八章学习笔记

Minor spanning tree

3 minutes learn to create Google account and email detailed tutorial!

2022-2028 global and Chinese equipment as a Service Market Research Report

介绍汉明距离及计算示例

Serpentine matrix

mxnet导入报各种libcudart*.so、 libcuda*.so找不到

MySQL in-depth learning - index creation and deletion, index design principles, index failure scenarios, query optimization, index push down ICP

可观测|时序数据降采样在Prometheus实践复盘

2022-2028 global and Chinese FPGA prototype system Market Research Report
随机推荐
概率论与数理统计考试重点复习路线
如何进行「小步重构」?
指针函数(基础)
托管式服务网络:云原生时代的应用体系架构进化
NetSetMan pro (IP fast switching tool) official Chinese version v5.1.0 | computer IP switching software download
Machine learning -- neural network
防护电路中的元器件
Construction d'un Cluster redis sous Windows
Solution of circular dependency
Scope of package class package
What are the building energy-saving software
Thematic information | carbon, carbon neutrality, low carbon, carbon emissions - 22.1.9
Sword finger offer 07 Rebuild binary tree
49 pictures and 26 questions explain in detail what is WiFi?
【thingsboard】替换首页logo的方法
[crampon programming] lintcode decoding Encyclopedia - 1100 strange printer
Wenet: E2E speech recognition tool for industrial implementation
[AI bulletin 20220211] the hard core up owner has built a lidar and detailed AI accelerator
Label exchange experiment
[Business Research Report] Research Report on male consumption trends in other economic times -- with download link