/*********
* groovy中Object类型存在隐式转换 可以不必使用as强转
*/
Object munber = 9.343444
def number1 = 2
println munber - number1 if (number1 < munber) {
println '转换了'
} /************
* 测试groovy中空字符串运算
*/
def str1 = "8"
def str2 = "-1"
def str3 = "*2" GroovyShell shell = new GroovyShell()
println shell.evaluate(str1 + str2)
println shell.evaluate(str1 + str3) /**
* 测试字符串
*/
def str5 = 'java'
def str6 = 'java '
println str5 == str6
println str5.trim() == str6.trim() /****
* 测试运算符号
*/ def num = 2
def num1 = 3
println num << num1 /****************
* 测试 进程
*/ println 'cmd /C dir'.execute().text /**************
* 安全导航操作符的使用
* ?. 操作符只有对象引用不为空时才会分派调用
*/
def str7 = null
def str8 = 'jiao' println str7?.reverse() // 不加问好会报错 空指针异常
println str8.reverse() /****
* 使用多赋值
*/
def fullName( fullname) {
fullname.split(' ')
}
def ( first, last ) = fullName ('jiao xi') println " $first , $last"
/***********
* 多赋值
* 多余的变量将会设置为null , 多余的值会被 丢弃 。
*/
def ( String cat , String mouse ) = [ 'Tom', 'Jerry', 'Tyke']
def ( String cat1 , String mouse1, String dog ) = [ 'Tom', 'Jerry']
println "$cat and $mouse "
println "$cat1 and $mouse1 and $dog " /**************
* groovy 中的bool值判定
*
* 类型 为真的条件
* Boolean 值为true
* Collection 集合不为空
* Character 值不为0
* CharSequence 长度大于0
* Iterator hasNext() 为true
* Number Double值不为0
* Map 该映射不为空
* Matcher 至少有一个匹配
* Object[] 长度大于0
* 其他任何类型 引用不为null
*
*/
/****
* 闭包懒加载
*/
def number = 1
def eagerGString = "value == ${number}"
def lazyGString = "value == ${ -> number }" assert eagerGString == "value == 1"
assert lazyGString == "value == 1" number = 2
assert eagerGString == "value == 1"
assert lazyGString == "value == 2"
/***********
* *操作符
*/
int function(int x, int y, int z) {
x*y+z
}
def args = [4,5,6]
assert function(*args) == 26
 

groovy程序设计的更多相关文章

  1. 推荐一本学习Groovy的书籍Groovy程序设计!

    有朋友公司在用groovy开发,于是推荐我学习一下,搜到了这本书: 花了一个月时间读完了这本书!写的很棒,几乎没有废话,全书都是很重要的知识点和很好的讲解,确实像封面说的那样,使用的好可以提高开发效率 ...

  2. 〖Groovy〗语言使用贴士(Tips)(转)

    [Groovy]是一门运行在[JVM]之上的动态语言.由[James Strachan]和[Bob McWhirter]于2003年启动开发,之后于2004年3月成为[JSR 241](Java Sp ...

  3. Java开发者职业生涯要看的200+本书

    作者:老刘链接:https://www.zhihu.com/question/29581524/answer/684872838来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明 ...

  4. 20145120 《Java程序设计》实验二实验报告

    20145120 <Java程序设计>实验二实验报告 实验名称:Java面向对象程序设计 实验目的与要求: 初步掌握单元测试和TDD 理解并掌握面向对象三要素:封装.继承.多态 初步掌握U ...

  5. 第一篇:groovy对DSL的语法支持

    引子 我们用一段gradle的脚本做引子,理解这一段脚本与一般的groovy代码是怎么联系起来的 buildscript { repositories { jcenter() mavenLocal() ...

  6. [转载] 详述三种现代JVM语言--Groovy,Scala和Clojure

    转载自http://www.tuicool.com/articles/jYzuAv和http://www.importnew.com/1537.html 在我与Martin Fowler曾经合作呈现的 ...

  7. ROS机器人程序设计(原书第2版)补充资料 (拾) 第十章 使用MoveIt!

    ROS机器人程序设计(原书第2版)补充资料 (拾) 第十章 使用MoveIt! 书中,大部分出现hydro的地方,直接替换为indigo或jade或kinetic,即可在对应版本中使用. MoveIt ...

  8. ROS机器人程序设计(原书第2版)补充资料 (柒) 第七章 3D建模与仿真 urdf Gazebo V-Rep Webots Morse

    ROS机器人程序设计(原书第2版)补充资料 (柒) 第七章 3D建模与仿真 urdf Gazebo V-Rep Webots Morse 书中,大部分出现hydro的地方,直接替换为indigo或ja ...

  9. 2017-2018-2 20165206 实验二《Java面向对象程序设计》实验报告

    2017-2018-2 20165206 实验二<Java面向对象程序设计>实验报告 一.实验报告封面 课程:Java程序设计 班级:1652班 姓名:韩啸 学号:20165206 指导教 ...

随机推荐

  1. Vue Router实现页面跳转拦截

    场景: 某些页面需要登录之后才可以访问,在页面跳转前做处理,如果要访问的页面A需要登录,则强制调到登录页,并且记录要访问的页面A的链接,在登录成功后自动跳转到页面A 1.在router下的index. ...

  2. Winform使用ML.NET时无法加载 DLL“CpuMathNative”问题的解决方法

    同样的代码运行在netcore下可以,运行在winform中就出现错误: 引发的异常:“System.DllNotFoundException”(位于 Microsoft.ML.Data.dll 中) ...

  3. GDAL OGR Tools

    OGR2OGR ogr2ogr 使用文档 1. GeoJSON 转换 ShapeFile ogr2ogr -nlt POLYGON -skipfailures ground.shp ground.js ...

  4. ubuntu14.04+安卓7.1(全志源码)+openjdk-8编译

    题记:编译花了将近4小时,所以编译源码是很费时的哦,可以在编译的时候可以学习其他的知识 编译环境准备 软件:WorkStation10 系统:ubuntu14.04 内存:8G 处理器:4个 磁盘大小 ...

  5. python的XML解析

    http://www.jb51.net/article/63780.htm http://www.runoob.com/python/python-xml.html http://kb.cnblogs ...

  6. spring boot starter是什么

    参考自:https://www.cnblogs.com/EasonJim/p/7615801.html Spring Boot中Starter是什么 比如我们要在Spring Boot中引入Web M ...

  7. etcd安全集群三节点扩容至四个节点

    规划:先安装三台组建集群,然后扩容一个安全节点进来 .环境: 三台centos7. 主机 192.168.0.91 192.168.0.92 192.168.0.93 都关闭防火墙 都关闭selinu ...

  8. H3C 模拟器 pc与sw直连 登录web

    配置与上一节相同 开启web功能,并登录 [sw1]ip http enable [sw1]local-user admin New local user added. [sw1-luser-mana ...

  9. C#在非UI线程调用UI线程的控件

    首先需要定义一个委托(delegate): private delegate void delegateSetProcessBarVal(int value); 然后定义一个方法来执行具体的操作: p ...

  10. java:shiroProject

    1.backend_system Maven Webapp:   LoginController.java: package com.shiro.demo.controller; import org ...