Groovy spread-dot operator
来源:互联网 发布:枭雄14g优化补丁 编辑:程序博客网 时间:2024/04/28 15:40
I’m unsure about when exactly I need to use the spread-dot operator. If I have a list such as:
def animals = ['ant', 'buffalo', 'canary', 'dog']
Because both animals and the members of the list have a size()
method, then in order to have the method invoked on the elements of the list (rather than the list itself), I need to use:
animals*.size()
rather than:
animals.size()
However, consider the following expression which returns a list of the method names that are available on the String
class
String.metaClass.methods.name
How does Groovy know (without using the spread-dot operator) that I want the name
property to be retrieved from each element of the list returned by String.metaClass.methods
, rather than the list itself? Is there a set of rules to use in this case such as:
If method/property exists on List
, invoke it on List
Otherwise try to invoke it for each element of List
The short answer is that DefaultGroovyMethods
adds a “getAt
” method to all Collections that iterates through the Collection and collects the property value for each.
- Groovy spread-dot operator
- Groovy的展开操作符(Spread Operator)*.和*
- Groovy的展开操作符(Spread Operator)*.和*
- What does operator “dot” (.) mean?
- ES6 展开运算符 Spread operator
- nodejs spread operator(三个点)
- react, Stateless Functions, ES6 花括号参数, Spread operator
- Spread
- Spread
- Groovy 1.8 新特性: Diamond operator 以及 DGM
- groovy
- groovy
- Groovy
- Groovy
- Groovy
- groovy
- groovy
- Groovy
- 【Hibernate】 缓存
- Jmeter之Bean shell使用(二)
- 读取assets目录下的图片
- 【干货分享】快速玩转Apple Pay开发
- AutoComplete.js输入智能提示插件
- Groovy spread-dot operator
- 给定一列字符,生成指定长度的所有可能的组合
- -128的原码和补码
- ANT批量执行Jmeter脚本
- java入门学习(13)—异常处理
- 搭建持续集成接口测试平台(Jenkins+Ant+Jmeter)
- list 基本操作 1 -- 创建,插入,删除,计算长度
- Binder是怎样成为Linux驱动程序的
- Jmeter默认报告优化