GROOVY简单语法实习
慢慢的看《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 = 1 def y = 2 assert x + y == 3 assert x.plus(y) == 3 assert x instanceof Integer def roman = ['', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII'] assert roman[4] == 'IV' roman[8] = 'VIII' assert roman.size() == 9 def http = [ 100 : 'CONTINUE', 200 : 'OK', 400 : 'BAD REQUEST' ] assert http[200] == 'OK' http[500] = 'INTERNAL SERVER ERROR' assert http.size() == 4 x = 1..10 assert x.contains(5) assert x.contains(15) == false assert x.size() == 10 assert x.from == 1 assert x.to == 10 assert x.reverse() == 10..1 [1, 2, 3].each { entry -> println entry } def totalClinks = 0 def partyPeople = 100 1.upto(partyPeople) { guestNumber -> clinksWithGuest = guestNumber - 1 totalClinks += clinksWithGuest } assert totalClinks == (partyPeople * (partyPeople - 1)) / 2 if (false) assert false if (null) { assert false } else { assert true } def i = 0 while (i < 10) { i++ } assert i == 10 def clinks = 0 for (remainingGuests in 0..9) { clinks += remainingGuests } assert clinks == (10*9)/2 def 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 }
GROOVY简单语法实习的更多相关文章
- Gradle Groovy 基础语法 MD
Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...
- 我的MYSQL学习心得(一) 简单语法
我的MYSQL学习心得(一) 简单语法 我的MYSQL学习心得(二) 数据类型宽度 我的MYSQL学习心得(三) 查看字段长度 我的MYSQL学习心得(四) 数据类型 我的MYSQL学习心得(五) 运 ...
- 编译原理简单语法分析器(first,follow,分析表)源码下载
编译原理(简单语法分析器下载) http://files.cnblogs.com/files/hujunzheng/%E5%8A%A0%E5%85%A5%E5%90%8C%E6%AD%A5%E7%AC ...
- PHP简单语法
PHP简单语法 声明变量 $var_name="1"; $var_num=1; $var_bool=true; var_dump"函数可以将我们的变量的数据类型显示出来. ...
- T-Sql(一)简单语法
原文:T-Sql(一)简单语法 Sql Server是鄙人学习的第一种数据库,对Sql Server有一种特别的情感,下面就说一下Sql Server的简单语法,适用初学者. 1,创建数据库creat ...
- 10.1 ES6 的新增特性以及简单语法
ES6 的新增特性以及简单语法 let 和 const 模板字符串 箭头函数 对象单体模式 es6面向对象 模块化 let 和 const 之前一直用 var 来声明变量,ES6 新增 let 和 ...
- MYSQL(一) 简单语法
MYSQL(一) 简单语法 1.默认约束:mysql里面DEFAULT关键字后面是不用加括号的 --1.1 创建数据库 mysql> create database holly; Query O ...
- groovy常用语法及实战
groovy语言简介 一种基于JVM的敏捷开发语言,作为编程语言可编译成java字节码,也可以作为脚本语言解释执行. 结合了Python.Ruby和Smalltalk的许多强大的特性 支持面向对象编程 ...
- wget下载简单语法
文章参考:https://linuxtools-rst.readthedocs.io/zh_CN/latest/tool/wget.html nasa wget 下载: https://disc.gs ...
随机推荐
- E20170626-hm
authenticate vt. 认证,证明是真实的.可靠的或有效的; 鉴定,使生效; author n. 作者; 著作家; 创造者; 发起人;
- struts2标签---备忘录
<s:form action="sloginAction" method="post"> <s:textfield label="用 ...
- [App Store Connect帮助]二、 添加、编辑和删除用户(5)创建一个沙盒测试员帐户
如果您的 App 使用了 App 内购买项目或 Apple Pay,您可以在 App Store Connect 中创建沙盒测试员帐户,以便您向用户提供该 App 前,可以使用该帐户在测试环境中运行您 ...
- Akka源码分析-local-DeathWatch
生命周期监控,也就是死亡监控,是akka编程中常用的机制.比如我们有了某个actor的ActorRef之后,希望在该actor死亡之后收到响应的消息,此时我们就可以使用watch函数达到这一目的. c ...
- BZOJ 4310 二分+SA+RMQ
思路: 首先求出后缀数组和height数组,这样能得到本质不同的子串数目 这里利用:本质不同的子串=∑(Len−SA[i]−height[i])=∑(Len−SA[i]−height[i])利用SA[ ...
- EF--ModelFirst
EF框架有三种基本的方式:DB First,Model First,Code First.这里简单的说一下Model First,适合没有基础的同学照着做,学习基础的东西. 1.建立一个类库项目,这个 ...
- C++ 由虚基类 虚继承 虚函数 到 虚函数表
//虚基类:一个类可以在一个类族中既被用作虚基类,也被用作非虚基类. class Base1{ public: Base1(){cout<<"Construct Base1!&q ...
- js的toFixed解惑
js中的toFixed,C#中的Math.round都是按照银行家算法的定义来算的,这里只拿js作参考,各个浏览器的计算方式并不一样,先看一张图,对比参数很容易就发现了其中的不同之处: 前三个Chro ...
- Spring Boot (23) Lettuce Redis
Spring Boot除了支持常见的ORM框架外,更是对常用的中间件提供了非常好的封装,随着SpringBoot2.x的到来,支持的组件也越来越丰富,也越来越成熟,其中对Redis的支持不仅仅是它丰富 ...
- Android 微信SDK图片分享(checkArgs fail, thumbData is invalid)
微信官网给的Demo中.图片的分享例子他是这么描述的: String url = "http://pic2.nipic.com/20090506/1478953_125254084_2.jp ...