[Training Video - 4] [Groovy] Optional parameter in groovy

Employee.log=log
Employee e1 = new Employee()

log.info e1.add(1,2,3,4)
// optional parameters in groovy
log.info e1.add(2,3)
log.info e1.add(2,3,10)

class Employee {
	def static log

	public def add(a,b,c=3,d=10){
		return a+b+c+d
	}
}

Run result:

Tue Oct 06 19:31:50 CST 2015:INFO:10
Tue Oct 06 19:31:50 CST 2015:INFO:18
Tue Oct 06 19:31:50 CST 2015:INFO:25
时间: 2024-12-28 08:24:24

[Training Video - 4] [Groovy] Optional parameter in groovy的相关文章

Groovy轻松入门——搭建Groovy开发环境

多日来,我发表了多篇关于Groovy的文章,想必大家对Groovy或多或少已经有所了解,今后我会抽空写些Groovy入门性质的文章,供大家参考.由于时间仓促,水平有限,不足之处请各位朋友多包涵提点,谢谢.既然是入门,我先不介绍那些IDE的东西,比如Eclipse中的Groovy插件(如果您迫不及待的话,可以先看一下安装Groovy的Eclipse插件),我先讲一下如何设置Groovy的环境变量(我目前所用的系统是Windows XP),最后运行一个Hello, world程序告终. Groovy

The expression being assigned to optional parameter `v2' must be a constant or default value

今天写代码的时候遇到一个问题以前没有遇到过的问题,就是当我给一个对象参数赋值默认值的时候,报错了,代码如下 public void ShowOrHiddenKuang(bool isShow,Vector2 v2=Vector2.zero){ kuang.gameObject.SetActive(isShow); kuang.transform.localPosition = v2; } 找了相关资料发现应该这么写 public void ShowOrHiddenKuang(bool isSho

[Training Video - 5] [Groovy Script Test Step - Collections, Exceptions] Exception Handling in groovy

def x = new String[3] x[0] = "A" x[1] = "B" x[2] = "C" log.info"XXXXXX 1" try{ x[3] = "D" // def z=9/0 }catch(Exception e){ log.info "Some error "+e.getMessage() // Use e.getMessage() to print ex

[Training Video - 4] [Groovy] Constructors in groovy, this keyword

Bank.log = log Bank b1 = new Bank() b1.name = "BOA" b1.minbalance = 100 b1.city="London" Bank b2 = new Bank() b2.name = "HSBC" b2.minbalance = 100 b2.city="LA" Bank b3 = new Bank("A",100,"X") log

[Training Video - 3] [Groovy in Detail] Non-static functions and Static functions,initializing log inside class,Objects and object referances

Planet.log = log log.info "starting" // we use class to create objects of a class Planet p1 = new Planet() Planet p2 = new Planet() Planet p3 = new Planet() //Planet.name = "Pluto" illegal Planet.shape = "Circle" p1.name = &q

[Training Video - 3] [Groovy in Detail] Non-static and Static variables in groovy

log.info "starting" // we use class to create objects of a class Planet p1 = new Planet() Planet p2 = new Planet() Planet p3 = new Planet() //Planet.name = "Pluto" illegal Planet.shape = "Circle" p1.name = "earth" /

[Training Video - 3] [Groovy in Detail] What is a groovy class ?

log.info "starting" // we use class to create objects of a class Planet p1 = new Planet() Planet p2 = new Planet() Planet p3 = new Planet() p1.name = "earth" p1.shape = "circle" p2.name = "jupiter" p2.shape = "

groovy入门()Groovy插件安装:Maven报Plugin execution not covered by lifecycle configuration

参考链接:http://www.cnblogs.com/rightmin/p/4945797.html 1.引入groovy的jar包 2.引入groovy编译插件 3.遇到问题 Plugin execution not covered by lifecycle configuration 4.解决办法 quickfix+删除重导入工程大法!! 下面是网上介绍的解决方法,下次遇到再试试: 5.附录代码 - eclipse开发Groovy代码,与java集成,maven打包编译 5.1.设置类路径

soapUI+groovy 接口测试之部分groovy使用记录

1, 写入值(30,31),更新到数据表的多条记录. sqlStr = "select column_id from 1dcq_shop_column2  where shop_id = '"+ db_Shop_id + "'" def dbSettings=[] def db_sub_column_id ="" sqlResult = sql.eachRow(sqlStr) { dbSettings << it.toRowResul