博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
GROOVY简单语法实习
阅读量:6917 次
发布时间:2019-06-27

本文共 1897 字,大约阅读时间需要 6 分钟。

慢慢的看《GROOVY IN ACTION》的一个中文节译本,根据上面的东东慢慢练习。

中文看起来确实比英文快好多。。。:)

Book gina = new Book('Groovy in Action')assert gina.getTitle() == 'Groovy in Action'assert getTitleBackwards(gina) == 'noitcA ni yvoorG'String getTitleBackwards(book) {    title = book.getTitle()    return title.reverse()}def groovyBook = new Book()groovyBook.setTitle('Groovy conquers the world')assert groovyBook.getTitle() == 'Groovy conquers the world'groovyBook.title = 'Groovy conquers the world'assert groovyBook.title == 'Groovy conquers the world'def nick = 'Gina'def book = 'Groovy in Action'assert "$nick is $book" == 'Gina is Groovy in Action'assert '12345' =~ /\d+/assert 'xxxxx' == '12345'.replaceAll(/\d/, 'x')def x = 1def y = 2assert x + y == 3assert x.plus(y) == 3assert x instanceof Integerdef roman = ['', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII']assert roman[4] == 'IV'roman[8] = 'VIII'assert roman.size() == 9def http = [    100 : 'CONTINUE',    200 : 'OK',    400 : 'BAD REQUEST' ]    assert http[200] == 'OK'http[500] = 'INTERNAL SERVER ERROR'assert http.size() == 4x = 1..10assert x.contains(5)assert x.contains(15) == falseassert x.size() == 10assert x.from == 1assert x.to == 10assert x.reverse() == 10..1[1, 2, 3].each { entry -> println entry }def totalClinks = 0def partyPeople = 1001.upto(partyPeople) { guestNumber ->    clinksWithGuest = guestNumber - 1    totalClinks += clinksWithGuest}assert totalClinks == (partyPeople * (partyPeople - 1)) / 2if (false) assert falseif (null) {    assert false} else {    assert true}def i = 0while (i < 10) {    i++}assert i == 10def clinks = 0for (remainingGuests in 0..9) {    clinks += remainingGuests}assert clinks == (10*9)/2def list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]for (j in list) {    assert j == list[j]}list.each() { item ->    assert item == list[item]}switch(3) {    case 1 : assert false; break    case 3 : assert true; break    default : assert false}

转载地址:http://goxcl.baihongyu.com/

你可能感兴趣的文章
Top 10 JavaScript编辑器,你在用哪个?
查看>>
数据访问层的优化思路
查看>>
饭后最该知道N件事
查看>>
一文教你看懂大数据的技术生态圈 Hadoop,hive,spark
查看>>
关于本地分区索引和索引组织表保证唯一性的限制
查看>>
MaxCompute Studio 2.8.1 新版本发布啦!
查看>>
《区块链原理、设计与应用》一2.5 认识上的误区
查看>>
当所有编程语言都在靠齐的时候
查看>>
苹果拥抱IBM背后:大数据推动手机行业洗牌
查看>>
无线广播可以毁灭物联网安全:信号干扰器及犯罪
查看>>
《并行计算的编程模型》一3.7.1 选择集合参与者
查看>>
百分点:利用大数据做智慧商业
查看>>
让你的软件永生的7个规则
查看>>
《中国人工智能学会通讯》——12.23 隐私保护
查看>>
物联网五大应用实例,一看便明了!!
查看>>
中国人工智能学会通讯——众包中的统计推断与激励机制 4 我们能否有更好的付钱方式...
查看>>
GitLab宣布支持Git大文件存储Git LFS
查看>>
联想王震宇:联想企业网盘3.5版本的功能亮点
查看>>
监控蓄电池 保障数据中心正常运营
查看>>
浅析自动化设备安装运维的发展方向
查看>>