Groovy 学习笔记 (五)
- (1..10).each{ log += it } 等价于 (1..10).each({ log += it })
- Closure声明方式之一是: reference.& (其中receiver是对象)

- def adder = { x, y -> return x+y } 等价于 adder(4, 3) 或 adder.call(2, 6)
- 文件读写更加简单:
- def file = new File(‘myFileName.txt’)
- for (line in file) println line
- 方法的最后一个语句得到的值作为返回值,所以return语句是可选的
- 异常不强制要求捕获
- for (it in aaa) 中,变量 aaa 可以是字符串,可以是对象,等等
def file = new File(‘myFileName.txt’)
for (line in file) println def file = new File(‘myFileName.txt’)
for (line in file) println line
By javafuns on September 9, 2009 at 21:50 ·
Views: 388 · Permalink · RSS
Categorized in: Scripts · Tagged with: grails, Groovy, Scripts
Categorized in: Scripts · Tagged with: grails, Groovy, Scripts


(