Groovy高效特性
//groovy 的高效特性
//1、弱数据类型
def i = 1
println i.getClass()//class java.lang.Integer
i = 'a'
println i.getClass()//class java.lang.String
//2、断言
//assert i.getClass()==Integer //Assertion failed:
//3、括号可选
println(i)//a
println i //a
//4、字符串
i = "a"
def s1 = 'hello gradle'
def s2 = "this is ${i} demo"
def s3 = '''study
this
programming
builder
tools'''
println s1 //hello gradle
println s2 //this is a demo
println s3 //保留了格式
//5、集合api
//list
def list = ["ant","maven"]
list << "gradle"
println list.size()//3
println list.getClass()//class java.util.ArrayList
println list.get(0)//ant
println list[0]//ant
//map
def map = ["tom":20,"jerry":10]
map.sofe="5"
println map.size()//3
println map.getClass()//class java.util.LinkedHashMap
println map.sofe//5
println map["sofe"]//5
//6、闭包
def wucan = {
println "无参闭包"
}
def youcan = {
name ->
println "参数是${name}"
}
def method1(Closure closure){
closure()
}
def method2(Closure closure) {
closure("tom")
}
method1(wucan)//无参闭包
method2(youcan)//参数是tom