`
rainy646556896
  • 浏览: 20488 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
社区版块
存档分类
最新评论

Ranges

 
阅读更多

使用Ranges

(left..right)

(left..>right)

(right..left)

 

assert (1..10).contains(5)
assert (1..10).size() == 10
assert (1..<10).size() == 9

def log = ''
for(element in (1..3)) {
  log += element
}
assert log == '123'

log = ''
(1..3).each{element ->
    log += element
}
assert log == '123'

//Date()
Date today = new Date()
def tomorrow = today - 1
assert (today..tomorrow).size() == 2

//swich		
def age = 36
def rank = 0
switch(age){
	case 1..10: 
		rank = 1
		break
	case 11..30:
		rank = 2
		break
	case 31..60:
		rank = 3
		break
	default:
		throw new IllegalArgumentException() 
}
assert rank == 3

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics