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. yum info 查不到nginx下载info的问题

    如果查看nginx信息提示nginx找不到,那么可以通过修改rpm源来进行后续步骤,执行命令:rpm -ivh http://nginx.org/packages/centos/6/noarch/RP ...

  2. (转) Deep Reinforcement Learning: Playing a Racing Game

    Byte Tank Posts Archive Deep Reinforcement Learning: Playing a Racing Game OCT 6TH, 2016 Agent playi ...

  3. nunjucks.js模板渲染

    直接用 script 引入文件: <script src="nunjucks.js"></script> 是使用 render 来直接渲染文件,这种方式支持 ...

  4. CMD规范

    define(function (require, exports, module) { module.exports = require('xx/xx/xx')({}); });

  5. 对char类型的理解以及对补码的理解分析

    今天遇到这样一个小程序,觉得当中有些问题很容易让人忽略的! 这个程序代码如下: 程序的结果为: 我想很多像我一样的小白可能才开始是想不明白为什么最后的结果是255吧!首先,我们得知道 strlen() ...

  6. [家里蹲大学数学杂志]第041期中山大学数计学院 2008 级数学与应用数学专业《泛函分析》期末考试试题 A

    1 ( 10 分 ) 设 $\mathcal{X}$ 是 Banach 空间, $f$ 是 $\mathcal{X}$ 上的线性泛函. 求证: $f\in \mathcal{L}(\mathcal{X ...

  7. less笔记

    koala工具 注释:    1./**/,可以被编译    2.//,不可以被编译 申明变量:    @box_width:300px;    .box{        width:@box_wid ...

  8. 在脚本中刷新impala元信息

    刷新impala元信息 impala-shell -q 'invalidate metadata' -i hslave1 impala-shell -q 'select count(*) from p ...

  9. nginx/Windows-1.9.3启动脚本

    启动nginx.bat @echo off D: cd D:\Program Files\nginx-1.9.3 tasklist | findstr /i "nginx.exe" ...

  10. JAVA设计模式之解释器模式

    在阎宏博士的<JAVA与模式>一书中开头是这样描述解释器(Interpreter)模式的: 解释器模式是类的行为模式.给定一个语言之后,解释器模式可以定义出其文法的一种表示,并同时提供一个 ...