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. Codeforces Round #163 (Div. 2)

    A. Stones on the Table \(dp(i)\)表示最后颜色为\(i\)的最长长度. B. Queue at the School 模拟. C. Below the Diagonal ...

  2. SpringMVC案例1——对User表进行CRUD操作

    ------------------------------------------------------------------web.xml--------------------------- ...

  3. ECShop函数列表大全

    lib_time.php gmtime() P: 获得当前格林威治时间的时间戳 /$0 server_timezone() P: 获得服务器的时区 /$0 local_mktime(hour=NULL ...

  4. Oracle 学习之路开始

    今年刚毕业,从毕业到现在工作正式工作四个多月了(实习的几个月就不算了).工作之中遇到的困难不少,学到的东西也不少:但是感觉学到的东西还是不够,毕竟java水很深啊. 现在工作中并不是每天都能学到新的东 ...

  5. SSH 创建证书认证

    *******chmod 600 195-tempuser.txt******* useradd tempusersu tempusercdmkdir .sshchmod 700 .sshcd .ss ...

  6. Oracle表空间不足

    Oracle临时表空间不足 -- 用户的缺省表空间.临时表空间 select t.username, t.default_tablespace, t.temporary_tablespace from ...

  7. 在CentOS 7中安装nginx服务器

    简要地介绍一下,如何在CentOS 7中安装nginx服务器  下载对应当前系统版本的nginx包(package) # wget  http://nginx.org/packages/centos/ ...

  8. 【Python与机器学习】:利用Keras进行多类分类

    多类分类问题本质上可以分解为多个二分类问题,而解决二分类问题的方法有很多.这里我们利用Keras机器学习框架中的ANN(artificial neural network)来解决多分类问题.这里我们采 ...

  9. 使用nginx部署Yii 2.0\yii-basic-app-2.0.5

    nginx.conf #user nobody;worker_processes 1; #error_log logs/error.log;#error_log logs/error.log noti ...

  10. winform画图闪烁问题

    问题:在winform程序的onpaint方法中画图, 连续画, 如鼠标移动时就要不断画图, 会闪烁. 解决方法:将要画图的部分放到一个自定义控件中, 自定义控件的onpaint方法里面画图, 然后再 ...