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

  • 關於本站
  • 免責聲明