Top Banner
A brief introduction to 11ACM 朱朱朱 Groovy
18

A brief introduction to 11ACM 朱旻申. Outline What is Groovy ? Differences between Groovy & Java About closure & Dagger Methods.

Jan 12, 2016

Download

Documents

Alice Jefferson
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: A brief introduction to 11ACM 朱旻申. Outline What is Groovy ? Differences between Groovy & Java About closure & Dagger Methods.

A brief introduction to

11ACM朱旻申

Groovy

Page 2: A brief introduction to 11ACM 朱旻申. Outline What is Groovy ? Differences between Groovy & Java About closure & Dagger Methods.

Outline

What is Groovy ? Differences between Groovy & Java About closure & Dagger Methods

Page 3: 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

Page 4: A brief introduction to 11ACM 朱旻申. Outline What is Groovy ? Differences between Groovy & Java About closure & Dagger Methods.

An Example

In Groovy :

In Java :

Page 5: A brief introduction to 11ACM 朱旻申. Outline What is Groovy ? Differences between Groovy & Java About closure & Dagger Methods.

Grammar vs Java

No “;”, “()” & “public” No constructor, no “return” No types, everything is an object Closure

Page 6: A brief introduction to 11ACM 朱旻申. Outline What is Groovy ? Differences between Groovy & Java About closure & Dagger Methods.

Grammar

Java without types

Page 7: A brief introduction to 11ACM 朱旻申. Outline What is Groovy ? Differences between Groovy & Java About closure & Dagger Methods.

Grammar

Loop

Page 8: A brief introduction to 11ACM 朱旻申. Outline What is Groovy ? Differences between Groovy & Java About closure & Dagger Methods.

Grammar

Use “?” to avoid NULL pointer call

Page 9: A brief introduction to 11ACM 朱旻申. Outline What is Groovy ? Differences between Groovy & Java About closure & Dagger Methods.

Closure

Codes in “{}”

Page 10: A brief introduction to 11ACM 朱旻申. Outline What is Groovy ? Differences between Groovy & Java About closure & Dagger Methods.

Closure in iteration

Page 11: A brief introduction to 11ACM 朱旻申. Outline What is Groovy ? Differences between Groovy & Java About closure & Dagger Methods.

Closure in iteration

Page 12: A brief introduction to 11ACM 朱旻申. Outline What is Groovy ? Differences between Groovy & Java About closure & Dagger Methods.

Dagger Methods

Short, small but efficient Mostly implemented by closure

Page 13: A brief introduction to 11ACM 朱旻申. Outline What is Groovy ? Differences between Groovy & Java About closure & Dagger Methods.

eachWithIndex

Running results :1 : a2 : b3 : c

Page 14: A brief introduction to 11ACM 朱旻申. Outline What is Groovy ? Differences between Groovy & Java About closure & Dagger Methods.

any & every

Running results :truefalse

Page 15: A brief introduction to 11ACM 朱旻申. Outline What is Groovy ? Differences between Groovy & Java About closure & Dagger Methods.

grep

[‘a’, ‘ab’]

[‘ab’]

Page 16: A brief introduction to 11ACM 朱旻申. Outline What is Groovy ? Differences between Groovy & Java About closure & Dagger Methods.

sort

Running results :7, 23, 2012

Page 17: A brief introduction to 11ACM 朱旻申. Outline What is Groovy ? Differences between Groovy & Java About closure & Dagger Methods.

References

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

Page 18: A brief introduction to 11ACM 朱旻申. Outline What is Groovy ? Differences between Groovy & Java About closure & Dagger Methods.

Thanks for listening !