logo
  • 教程列表
  • SO官方文档
  • 三元和猫王运算符
    • 标准形式与猫王形式
    • 分配中的用法(有条件)
  1. StackOverflow 文档
  2. groovy 教程
  3. 三元和猫王运算符
  4. 分配中的用法(有条件)

分配中的用法(有条件)

Created: November-22, 2018

def results = []
(1..4).each{
    def what = (it%2) ? 'odd' :  'even'
    results << what
}
assert results == ['odd', 'even', 'odd', 'even']

在这里,if-condition(在 (parentheses) 中)比仅仅测试存在/ Groovy-Truth 稍微复杂一些。

  • 标准形式与猫王形式

Copyright © 2018. All right reserved

tastones.com 备案号:鲁ICP备18045372号-1

  • 关于我们
  • 免责声明