Groovy basic
1. print
println "Hello Groovy!"
you can use java in Groovy
System.out.println("Hello Groovy!");
2. define variable
Groovy is dynamically typed, type is optional
def foo = 6.5
you can define type if you want
int foo2=7
3. use expression in string
variable or expression start with dollar sign inside of the string
// variable in string
println "foo has value: $foo"
// expression in string
println "Let's do some math. 5 + 6 = ${5 + 6}"
// foo is variable, abc is literal
println "${foo+"abc"}"
4. define function
def doubleIt(n) {
n + n // Note we don't need a return statement
}
5. call function
for functions with 1+ args, we can call it without parenthese
def noArgs() {
println "Called the no args function"
}
def oneArg(x) {
println "Called the 1 arg function with $x"
x
}
def twoArgs(x, y) {
println "Called the 2 arg function with $x and $y"
x + y
}
oneArg 500 // Look, Ma! No parentheses!
twoArgs 200, 300
noArgs()
//noArgs // Doesn't work
//twoArgs oneArg 500, 200 // Also doesn't work as it's ambiguous
twoArgs oneArg(500), 200 // Fixed the ambiguity
Groovy basic的更多相关文章
- 快速创建maven 工程:simple java工程,webapp
http://www.cnblogs.com/buhaiqing/archive/2012/11/04/2754187.html 会从maven的Repository里查找所有支持的arche typ ...
- 如何使用Maven的archetype快速生成一个新项目(解决生成项目目录不完整问题)
Maven的archetype Plugin可能大家都听过,但不一定都能很好地用好它.缺省地如果你使用 mvn archetype:generate 会从maven的Repository里查找所有支 ...
- 6.Jenkins进阶之流水线pipeline语法入门学习(1)
目录一览: 0x00 前言简述 Pipeline 介绍 Pipeline 基础知识 Pipeline 扩展共享库 BlueOcean 介绍 0x01 Pipeline Syntax (0) Groov ...
- Groovy 模版引擎
1. Introduction Groovy supports multiple ways to generate text dynamically including GStrings, print ...
- 错误异常 (1)Android Studio错误提示:Gradle project sync failed. Basic functionality (eg. editing, debugging) will not work properly
[已解决]Android Studio错误提示:Gradle project sync failed. Basic functionality (eg. editing, debugging) wil ...
- Use Eclipse to develop groovy[docs.codehaus.org]
http://docs.codehaus.org/display/GROOVY/Install+Groovy-Eclipse+Plugin http://docs.codehaus.org/displ ...
- 使用yaml+groovy实现Java代码可配置化
背景与目标 在使用函数接口和枚举实现配置式编程(Java与Scala实现),使用了函数接口和枚举实现了配置式编程.读者可先阅读此文,再来阅读本文. 有时,需要将一些业务逻辑,使用配置化的方式抽离出来, ...
- Android Studio错误提示:Gradle project sync failed. Basic functionality (eg. editing, debugging) will not work properly
Android Studio中出现提示: Gradle project sync failed. Basic functionality (eg. editing, debugging) will n ...
- 【转载】Gradle学习 第九章:Groovy快速入门
转载地址:http://ask.android-studio.org/?/article/17 To build a Groovy project, you use the Groovy plugin ...
随机推荐
- ✡ leetcode 165. Compare Version Numbers 比较两个字符串数字的大小 --------- java
Compare two version numbers version1 and version2.If version1 > version2 return 1, if version1 &l ...
- PHP聊天室框架
内容和教程可以在这个网址查看 http://www.workerman.net/workerman-chat
- MongoDB学习笔记四:索引
索引就是用来加速查询的.创建数据库索引就像确定如何组织书的索引一样.但是你的优势是知道今后做何种查询,以及哪些内容需要快速查找.比如:所有的查询都包括"date"键,那么很可能(至 ...
- django 过滤器 、日期格式化参数
http://blog.csdn.net/xyp84/article/details/7945094 django1.4 html页面从数据库中读出DateTimeField字段时,显示的时间格式和数 ...
- Java注释Override、Deprecated、SuppressWarnings详解(过时方法,即将删除的方法或成员变量)
Override 这个注释的作用是标识某一个方法是否覆盖了它的父类的方法.那么为什么要标识呢?让我们来看看如果不用Override标识会发生什么事情. Deprecated 这个注释是一个标记注释.所 ...
- docker跨容器之使用link大法通信
容器1 docker run --name elixir -it edib/elixir-phoenix-dev /bin/bash ip address看看自己的ip 容器2 docker run ...
- Access使用参数化UPDATE数据时,数据无法更新的问题
今天update access数据库时,使用了参数化的方式,结果不报错,但是数据也没有更新.经过google发现access使用参数化时,参数位置必须和赋值顺序相同才行,否则更新时就会出现数据无法更新 ...
- 自动装箱(boxing)和自动拆箱(unboxing)
摘自:http://www.codeceo.com/article/java-boxing-unboxing.html Java的四类八种基本数据类型 基本类型 占用空间(Byte) 表示范围 包装器 ...
- EF 示例
EF有三种数据库访问方式,这里只介绍Code First. 1.DB First,类似Linq to sql中拖拽一个DB到方案中 2.Model First,没试过,不能自动生成数据库只能生成表 3 ...
- 65. Reverse Integer && Palindrome Number
Reverse Integer Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, re ...