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 ...
随机推荐
- 11g RAC集群启动关闭、各种资源检查、配置信息查看汇总。
简要:一:集群的启动与关闭 1. rac集群的手动启动[root@node1 bin]# ./crsctl start cluster -all2. 查看rac集群的状态[root@node1 bin ...
- C#中的async和await
其实这两个关键字的功效比之前的异步方法调用有一个好处,那就是异步阻塞的方法可以有返回值.之前都是通过回调函数实现,执行上下文会切换,不过和这个执行过程类似.可以对这两个关键字这么理解:遇到async的 ...
- Python decode与encode
字符串在Python内部的表示是unicode编码(8-bit string),因此,在做编码转换时,通常需要以unicode作为中间编码,即先将其他编码的字符串解码(decode)成unicod ...
- 完成一段简单的Python程序,用于实现一个简单的加减乘除计算器功能
#!/bin/usr/env python#coding=utf-8'''完成一段简单的Python程序,用于实现一个简单的加减乘除计算器功能'''try: a=int(raw_input(" ...
- 第一节:简单的请求(Requests)和响应(Responses)
目录 创建项目 开发服务器 创建名称为Polls的应用 编写你的第一个视图 创建项目 在命令行中,使用cd命令进入到你想要存储你的项目的目录,然后运行下面的命令: $ django-admin sta ...
- nodejs项目在webstorm里进行debug的设定
菜单 > Run > Edit Configurations... 菜单 > Run > Debug... 菜单 > Run > Edit Configuratio ...
- 正则匹配<{$vcode}>变量
$title="<{t}>您的验证码是:<{/t}><{$vcode}>,<{t}>请在注册页输入验证码并完成注册:验证码<{$vcod ...
- 7个混合式HTML5移动开发框架
在这个时间开始学习移动开发真是最好不过了,每个人应该都有一些移动应用的创意,而且你并不需要任何的原生应用编程经验,你只需要一些HTML的相关知识,懂一些CSS和JavaScript就够了.如果你总听别 ...
- Ubuntu 安装 Xfce4 桌面
sudo apt-get install xubuntu-desktop From: http://tieba.baidu.com/p/294762291
- HTML中行内元素与块级元素的区别
块级元素:独占一行,可设宽高,内外边距:块级元素有form,p,h1到h6,ol ,ul ,dl和dd和dt ,hr,li,pre,caption ,div ,table ,tr ,td ,th等. ...