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的更多相关文章

  1. 快速创建maven 工程:simple java工程,webapp

    http://www.cnblogs.com/buhaiqing/archive/2012/11/04/2754187.html 会从maven的Repository里查找所有支持的arche typ ...

  2. 如何使用Maven的archetype快速生成一个新项目(解决生成项目目录不完整问题)

    Maven的archetype Plugin可能大家都听过,但不一定都能很好地用好它.缺省地如果你使用 mvn archetype:generate  会从maven的Repository里查找所有支 ...

  3. 6.Jenkins进阶之流水线pipeline语法入门学习(1)

    目录一览: 0x00 前言简述 Pipeline 介绍 Pipeline 基础知识 Pipeline 扩展共享库 BlueOcean 介绍 0x01 Pipeline Syntax (0) Groov ...

  4. Groovy 模版引擎

    1. Introduction Groovy supports multiple ways to generate text dynamically including GStrings, print ...

  5. 错误异常 (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 ...

  6. Use Eclipse to develop groovy[docs.codehaus.org]

    http://docs.codehaus.org/display/GROOVY/Install+Groovy-Eclipse+Plugin http://docs.codehaus.org/displ ...

  7. 使用yaml+groovy实现Java代码可配置化

    背景与目标 在使用函数接口和枚举实现配置式编程(Java与Scala实现),使用了函数接口和枚举实现了配置式编程.读者可先阅读此文,再来阅读本文. 有时,需要将一些业务逻辑,使用配置化的方式抽离出来, ...

  8. 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 ...

  9. 【转载】Gradle学习 第九章:Groovy快速入门

    转载地址:http://ask.android-studio.org/?/article/17 To build a Groovy project, you use the Groovy plugin ...

随机推荐

  1. myeclipse启动tomcat报错cannot find a free socket for debugger

    解决办法,命令行输入netsh winsock reset,winsock是Windows网络编程接口,winsock工作在应用层,它提供与底层传输协议无关的高层数据传输编程接口 netsh wins ...

  2. mysql-创建库之问题

    一.在登入mysql命令行,创建数据库时报错 ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'xiaolu ...

  3. Jquery tab 选项卡 无刷新切换

    转载的 演示地址:http://www.freejs.net/demo/29/index.html 首页>>TAB标签>>jquery实现简单的Tab切换菜单(2013-09- ...

  4. MSSQL 生成拼音码

    MSSQL 生成拼音码 /*============================================================================== 名称:fn_G ...

  5. Win7 Update 遭遇8024200D

    可用办法如下: 1.点击开始菜单,点运行,输入cmd然后按回车.然后在命令行下输入: net stop WuAuServ 2.点击开始菜单,点运行,输入%windir%然后按回车. 3.在打开的文件夹 ...

  6. Mustache 使用心得总结

    Mustache 使用心得总结 前言: 之前的一个项目里面就有用到这个前台的渲染模版,当时挺忙的也没时间抽空总结一下,刚好上周项目里又用到这个轻量型的渲染模版,真心感觉很好用,因此就总结一下使用心得, ...

  7. Python - 异步IO\数据库\队列\缓存

    协程 协程,又称微线程,纤程.英文名Coroutine.一句话说明什么是线程:协程是一种用户态的轻量级线程,协程一定是在单线程运行的. 协程拥有自己的寄存器上下文和栈.协程调度切换时,将寄存器上下文和 ...

  8. Spring MVC小结

    Spring MVC项目搭建 添加依赖 (省略) Spring MVC配置类 @Configuration @EnableWebMvc @ComponentScan("com.sjx.spr ...

  9. java内存溢出分析(二)

    我们继续java内存溢出分析(一)的分析,点击Details>按钮,显示如下图,我们发现有一个对象数量达到280370216个,再点击其中的List objects 点击后,显示下图 至此,我们 ...

  10. ASP.NET Page对象各事件执行顺序(转)

    很久没写 asp.net 的东西了,search 了一下 page 的事件执行顺序,找到如下的东西,仅仅做记录用 Page.PreInit 在页初始化开始时发生 Page.Init 当服务器控件初始化 ...