groovy之基础篇
发布时间:2020-12-14 17:04:58 所属栏目:大数据 来源:网络整理
导读:package fist class HelloWorld {??static main(args) {??println("===========HelloWorld "+new java.util.Date());??System.out.println("HI GROOVY");????def var="YES";??println var;??println var.class;??var=1000;??println var.class;????println("
package fist class HelloWorld { ? ?static main(args) { ??println("===========HelloWorld "+new java.util.Date()); ??System.out.println("HI GROOVY"); ?? ??def var="YES"; ??println var; ??println var.class; ??var=1000; ??println var.class; ?? ??println("MAP------------------");? ??def map=['name':'VerRan','age':'25']; ??println map['name']; ??println map.age; ??map.wife='dove'; ??println map.wife; ?? ??map.each({println it}); ??map.each({key,value->println "$key:$value"}); ?? ??println("Collect集合------------------"); ??def collect=['a','b','c']; ??println collect[1]; ??println collect.size; ??println collect[-2]; ?? ??println("闭包------------------"); ??def say={world-> ???println "come on 闭包,$world"; ???} ??say("HIIIIIIII"); ?} } class Sencod extends GroovyTestCase { public void test(){ def animals=['dog','maomi','caw','cat']; assert animals.size()==4; assert animals.get(1)=="maomi"; def add={ a,b-> return a+b; } def c=add.call(1,2); assert c==3; def values=animals.find{it.size()>3}; assert values=="maomi"; println animals.every({it.size()>3}); println animals.any({it.size()>3}); println animals.min(); println animals.max(); println animals.join (";"); } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |