Download ppt - Groovy Intro

Transcript
Page 1: Groovy Intro

Infor Confidential Copyright © 2001-2008 Infor Global Solutions

Groovy: Fly Beyond Java

Page 2: Groovy Intro

2

Agenda

Why Groovy Appears

How Groovy Rocks

Page 3: Groovy Intro

3

什么是好的程序语言?

Page 4: Groovy Intro

4

CEO的梦想

=

Page 5: Groovy Intro

5

程序员的梦想

写程序 泡网 午饭

和美眉网聊

打游戏 下班

Page 6: Groovy Intro

6 Copyright © 2001-2006 Infor Global Solutions

哪种编程语言更“好”?

义義好的编程语言也许应该更像是一门

“语言”

Page 7: Groovy Intro

7 Copyright © 2001-2006 Infor Global Solutions

于是 Groovy诞生了

Groovy使得 Java更“语言”

Java的强大技术

类 Ruby等动态语言的轻盈语法Groovy

Page 8: Groovy Intro

8 Copyright © 2001-2006 Infor Global Solutions

欢迎来到简洁美妙的Groovy世界

Page 9: Groovy Intro

9 Copyright © 2001-2006 Infor Global Solutions

别在乎类型

Java:

String name = “abc”;

Groovy:

String name = “abc”def namename = “abc”

Page 10: Groovy Intro

10 Copyright © 2001-2006 Infor Global Solutions

“直接”访问属性

class Person { private String name; public Person(String name) {this.name = name;} public String getName() {return name;}}

Person person = new person(“ocean”)return person.getName();

class Person { String name;}Person person = new Person(name:”ocean”)return person.name

Page 11: Groovy Intro

11 Copyright © 2001-2006 Infor Global Solutions

了不起的字符串

firstName = “ocean”lastName = “dong”message = “My name is $firstName $lastName”

person = new Person()person.setName(“ocean”)message = “My name is ${person.name}”

Message = “““Hi,My name is ${person.name}”””

def pattern = /hello\b.*/

Page 12: Groovy Intro

12 Copyright © 2001-2006 Infor Global Solutions

集合:简单类型而已

List:

def aList = [1, 2, 3]def aList = [10, “abc”, new Date()]

Map:def aMap = [a:1, b:2]

Range:def aRange = ‘a’..’z’def numbers = 0..<10

Page 13: Groovy Intro

13 Copyright © 2001-2006 Infor Global Solutions

可爱的操作符

[1, 2, 3] << 4

def aMap = [a:1, b:2]println aMap.aprintln aMap[a]

“hello world” =~ /hello\b.*/

println person?.wife?.name

Page 14: Groovy Intro

14 Copyright © 2001-2006 Infor Global Solutions

万物皆可判断

If(1)assert 1

def aList = [1, 2, 3]If(aList)assert aList

def personIf(person)assert !person

Page 15: Groovy Intro

15 Copyright © 2001-2006 Infor Global Solutions

四通八达的 Switch

switch(10) {case 0:case 0..9:case [8,9,11]:case Float:case {it % 3 == 0}:case ~/../:default:

}

Page 16: Groovy Intro

16 Copyright © 2001-2006 Infor Global Solutions

透明的集合

ArrayList names = new ArrayList()for(Person person : persons) {

names.add(person.getName());}return names;

def persons = [new Person(”ocean”), new Person(”coco”)]assert persons.name == [“ocean”, “coco”]assert persons*.getGender() == [“Male”, “Female”]

Page 17: Groovy Intro

17 Copyright © 2001-2006 Infor Global Solutions

Closure: 终极代码重用

ArrayList persons = …for(Person person : persons) {

System.out.println(person.getName());}

persons.each {it -> println it.name}

Page 18: Groovy Intro

18 Copyright © 2001-2006 Infor Global Solutions

远远不止这些哦。。。

Builder

Meta Programming

Groovylet

GSP

GRailsScriptom

Griffon

GMaven

Gant

GSQL

GORM

Tellurium

http://groovy.codehaus.org/

Page 19: Groovy Intro

19

Thanks