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. java 压缩文件 传入文件数组,压缩文件,在指定路径下生成指定文件名的压缩文件

    /** * 传入文件数组,压缩文件,在指定路径下生成指定文件名的压缩文件 * * @param files * 文件数组 * @param strZipName * 压缩文件路径及文件名 * @thr ...

  2. C#常见控件命名规则举例

    控件       缩写  举例 Adrotator adrt adrtTopAd BulletedList blst blstCity Button btn btnSubmit Calendar ca ...

  3. RestEasy 3.x 系列之一:Hello world

    RestEasy 3.x改了不少,走了好多弯路才终于搞出来,做做笔记,陆续发布…… tomcat-7.0.50 java version "1.7.0_51" myeclipse ...

  4. EDIUS校正颜色轮的方法

    小伙伴平时肯定能在网络上看到各种各样的视频吧,它们有的搞笑,有的炫酷,有的教育......那么你们有没有想过做出带有自己创意的视频呢?其实这个愿望很容易实现的,学好一款视频编辑软件就可以了.今天小编就 ...

  5. ASP.NET SignalR 与 LayIM2.0 配合轻松实现Web聊天室(十四)之漏掉的客服消息

    前言 不知不觉已经十四篇了,其实已经没有什么可写了.但是突然发现layim中带的客服功能没有用到.于是乎,抽点时间完成吧.其实之前的工作已经把客服功能完成了一大半,剩下的我们稍微调整即可.今天的演示我 ...

  6. Property ClientHeight does not exist 问题解决

    delphi的TFrame继承自另一个TFrame时,最好通过File->New->Other...->Delphi Projects->Inheritable Items 的 ...

  7. web中session与序列化的问题

    最近在写网上商城项目的时候学习了一个关于session的序列化问题,过来总结一下. 众所周知,session是服务器端的一种会话技术,只要session没有关闭,一个会话就会保持.这里先引出一个问题: ...

  8. 编译错误:error: multi-line comment

    编译错误:error: multi-line comment  这其实是有宏定义的地方的问题. 原因是宏定义非一行,在宏定义的行尾使用 '\' 连接符导致的. 所以这个地方的注释使用 /*   */ ...

  9. WPF绑定数据源

    using System;using System.Collections.Generic;using System.Collections.ObjectModel;using System.Comp ...

  10. 在win下开发c++代码, 推荐一个工具dev c++

    官方地址:http://bloodshed-dev-c.en.softonic.com/