码迷,mamicode.com
首页 > 其他好文 > 详细

Groovy学起来,这要和GRAILS,RUNDECK打成一片

时间:2015-07-18 21:10:04      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:

还好,以前看过RUBY和JAVA,GROOVY感觉和它们有点相似。。

并且,我觉得这个GROOVY比SCALA要简单些(函数式编程+OBJ)

作类比,毕竟是最快的学习方法。

XXX,还有必修课和证券从员人员资格考试,这段时间有点满了哈,,

明晚跟篮球兄弟们喝酒,还有《黑客军团》要跟进呢。。。

实习了一下GROOVY的代码,三天不学习,跟不上刘少奇!!!

def message = 12
println message

def repeat(val, repeat = 5){
    for(i in 0 ..< repeat){
        println val
    }
}

repeat("hello world")
repeat("Goodbye sunshine", 4)

def range = 0 .. 4
println range.class

assert range instanceof List

def coll = ["Groovy", "Java", "Ruby", "Python"]
assert coll instanceof Collection
assert coll instanceof ArrayList

coll.add("Perl")
coll << "Smalltalk"
coll[6] = "Ada"
assert coll[1] == "Java"

def numbers = [1, 2, 3, 4]
assert numbers + 5 == [1, 2, 3, 4, 5]
assert numbers - [2, 3] == [1, 4] 
assert numbers.join(",") == "1,2,3,4"
assert [1, 2, 3, 4, 3].count(3) == 2

assert ["JAVA", "GROOVY"] ==
  ["Java", "Groovy"]*.toUpperCase()
  
  
def hash = [name:"Andy", "VPN-#":45]
assert hash.getClass() == java.util.LinkedHashMap
//hash.put(id, 23)
assert hash.get("name") == "Andy"
hash.dob = "01/29/76"
assert hash.dob == "01/29/76"

def acoll = ["Groovy", "Java", "Ruby"]

for (Iterator iter = acoll.iterator(); iter.hasNext();){
    println iter.next()
}
acoll.each{ value->
    //println it
    println value
}

hash.each {key, value ->
    println "${key}":"${value}"
}

"ITERATION".each{
    print it.toLowerCase()
}

def excite = { word->
    return "${word}!!"
}

assert "Groovy!!" == excite("Groovy")

输出图示:

技术分享

 

Groovy学起来,这要和GRAILS,RUNDECK打成一片

标签:

原文地址:http://www.cnblogs.com/aguncn/p/4657510.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!