A brief introduction to 11ACM 朱旻申
Outline What is Groovy ? Differences between Groovy & Java About closure & Dagger Methods
Groovy … An agile and dynamic language for the Java Virtual Machine Builds upon the strengths of Java but has additional power features inspired by languages like Python, Ruby and Smalltalk Provides the ability to statically type check and statically compile your code
An Example In Groovy : In Java :
Grammar vs Java No “;”, “()” & “public” No constructor, no “return” No types, everything is an object Closure
Grammar Java without types
Grammar Loop
Grammar Use “?” to avoid NULL pointer call
Closure Codes in “{}”
Closure in iteration
Dagger Methods Short, small but efficient Mostly implemented by closure
eachWithIndex Running results : 1 : a 2 : b 3 : c
any & every Running results : true false
grep [‘a’, ‘ab’] [‘ab’]
sort Running results : 7, 23, 2012
References Wikipedia 百度文库