Groovy的隐藏功能? [英] Hidden features of Groovy?

查看:119
本文介绍了Groovy的隐藏功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看来Groovy在这个线程中被遗忘了,所以我只会问Groovy的同一个问题。


  • 尝试限制回答到Groovy核心

  • 每个答案的一个功能

  • 给出功能的示例和简短描述,而不仅仅是文档链接

  • 使用加粗标题作为第一行标记功能


另见:


  1. Python的隐藏功能 li>
  2. Ruby的隐藏功能

  3. Perl的隐藏功能

  4. < a href =https://stackoverflow.com/questions/15496/hidden-features-of-java> Java的隐藏功能


解决方案

使用spread-dot op erator

  def animals = ['ant','buffalo','canary','dog'] 
assert animals.size()== 4
assert animals * .size()== [3,7,6,3]

这是 animals.collect {it.size()} 的快捷方式。


It seems like Groovy was forgotten in this thread so I'll just ask the same question for Groovy.

  • Try to limit answers to Groovy core
  • One feature per answer
  • Give an example and short description of the feature, not just a link to documentation
  • Label the feature using bold title as the first line

See also:

  1. Hidden features of Python
  2. Hidden features of Ruby
  3. Hidden features of Perl
  4. Hidden features of Java

解决方案

Using the spread-dot operator

def animals = ['ant', 'buffalo', 'canary', 'dog']
assert animals.size() == 4
assert animals*.size() == [3, 7, 6, 3]

This is a shortcut for animals.collect { it.size() }.

这篇关于Groovy的隐藏功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆