大佬教程收集整理的这篇文章主要介绍了GDK对Object对象的扩展,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
Groovy添加了若干方法到java.lang.object
当中,其中大部分处理类型作为集合或聚合,如列表或DOM节点。
Return Value |
@H_882_6@method | Description |
---|---|---|
Boolean |
returns |
|
List |
returns a list of all items that were returned from the closure |
|
Collection |
same as above,but adds each item to the given collection |
|
void |
simply executes the closure for each item |
|
void |
same as each{} except it passes two arguments: the item and the index |
|
Boolean |
returns |
|
Object |
returns the first item that matches the closure expression |
|
List |
returns all items that match the closure expression |
|
returns the index of the first item that matched the given expression |
def numbers = [ 5,7,9,12 ] assert numbers.any { it % 2 == 0 } //returns true since 12 is even原文地址 http://groovy.codehaus.org/GDK+Extensions+to+Objectassert numbers.every { it > 4 } //returns true since all #s are > 4
assert numbers.findAll { it in 6..10 } == [7,9] //returns all #s > 5 and < 11
assert numbers.collect { ++it } == [6,8,10,13] //returns a new list with each # incremented
numbers.eachWithIndex{ num,idx -> println "$idx: $num" } //prints each index and number
以上是大佬教程为你收集整理的GDK对Object对象的扩展全部内容,希望文章能够帮你解决GDK对Object对象的扩展所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。