A brief introduction to 11ACM 朱旻申. Outline What is Groovy ? Differences between Groovy &...

Preview:

Citation preview

A brief introduction to

11ACM朱旻申

Groovy

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

Closure in iteration

Dagger Methods

Short, small but efficient Mostly implemented by closure

eachWithIndex

Running results :1 : a2 : b3 : c

any & every

Running results :truefalse

grep

[‘a’, ‘ab’]

[‘ab’]

sort

Running results :7, 23, 2012

References

http:\\groovy.codehaus.org Wikipedia百度文库

Thanks for listening !