还好,以前看过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")
输出图示:
时间: 2024-11-03 03:51:18