[Training Video - 3] [Groovy in Detail] Non-static and Static functions, initializing log inside class
log.info "starting" // we use class to create objects of a class
Planet p1 = new Planet()
Planet p2 = new Planet() //Planet.name = "Pluto" illegal
Planet.shape = "Circle" // static variable
Planet.log = log p1.name = "earth" // non static variable
p2.name = "jupiter" p1.printName() // non static has to be called with reference
Planet.revolve() // static can be called with class class Planet{
// variables and functions
def name // non static variable
def static shape // static variable
def static log public void printName(){ // non static function
log.info ("Name of planet is $name. Shape is $shape")
xyz() // non static can access static
} public static void revolve(){ // static function
//log.info (name) // error, static cannot access non static
xyz() // call one function from another function
log.info ("Planet revolving. Shape is $shape")
} public static void xyz(){
log.info "inside xyz"
}
}
Test Result:
Tue Oct 06 18:30:29 CST 2015:INFO:starting
Tue Oct 06 18:30:29 CST 2015:INFO:Name of planet is earth. Shape is Circle
Tue Oct 06 18:30:29 CST 2015:INFO:inside xyz
Tue Oct 06 18:30:29 CST 2015:INFO:inside xyz
Tue Oct 06 18:30:29 CST 2015:INFO:Planet revolving. Shape is Circle
Note :
Static cannot access non static
[Training Video - 3] [Groovy in Detail] Non-static and Static functions, initializing log inside class的更多相关文章
- [Training Video - 3] [Groovy in Detail] Non-static and Static variables, objects and object referances
		
log.info "starting" // we use class to create objects of a class Planet p1 = new Planet() ...
 - [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() ...
 - [Training Video - 4] [Groovy] Function in detail
		
Employee.log=log Employee e1 = new Employee() Employee e2 = new Employee() e1.name = "A" e ...
 - [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 gro ...
 - [Training Video - 2] [Groovy Introduction]
		
Building test suites, Test cases and Test steps in SOAP UI Levels : test step level test case level ...
 - [Training Video - 4] [Groovy] Constructors in groovy, this keyword
		
Bank.log = log Bank b1 = new Bank() b1.name = "BOA" b1.minbalance = 100 b1.city="Lond ...
 - [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"X ...
 - [Training Video - 5] [Groovy Script Test Step - Collections, Exceptions] HashSet and Hashtable
		
Hashset: HashSet set = new HashSet() set.add("India") set.add("USA") set.add(&qu ...
 - [Training Video - 5] [Groovy Script Test Step - Collections, Exceptions] Array and ArrayList
		
Array: def x = new String[5] x[0] = "India" x[1] = "USA" x[2] = "Korea" ...
 
随机推荐
- Renesas APIs ***
			
一个线程,强行结束另外一个线程,并将其挂起: static void SuspendTask(TX_THREAD *thread) { UINT status = ; UINT state; stat ...
 - rails里面添加妹子ui
			
妹子ui看起来很不错,以为在rails里面添加自定义的css和js和平时一样,结果可想而知,不过弄完以后发现还是比较简单的,这里记录一下 妹子ui需要加载的css和js如下 http://cdn.am ...
 - linux命令ls -l的默认排序方式
			
差不多快实现完了ls -l,但是在测试阶段发现一个问题,对于包含[a-ZA-Z]之外的字符,系统的排序方式并不一样. 很想了会儿,总算发现原来它的排序方式是无视[a-ZA-Z]之外的字符的 至于怎么发 ...
 - 【学习笔记】dp基础
			
知识储备:dp入门. 好了,完成了dp入门,我们可以做一些稍微不是那么裸的题了. dp基础,主要是做题,只有练习才能彻底掌握. 洛谷P1417 烹调方案 分析:由于时间的先后会对结果有影响,所以c[i ...
 - Dev使用技巧汇总
			
C# XtraGrid的行指示器(RowIndicator)行号以及图标设置 参考网址:https://www.cnblogs.com/xuliangxing/p/6775438.html DateE ...
 - 深入浅出 Java Concurrency (12): 锁机制 part 7 信号量(Semaphore)
			
Semaphore 是一个计数信号量.从概念上讲,信号量维护了一个许可集.如有必要,在许可可用前会阻塞每一个 acquire(),然后再获取该许可.每个 release() 添加一个许可,从而可能 ...
 - STL之父Stepanov谈泛型编程的发展史
			
这是一篇Dr. Dobb's Journal对STL之父stepanov的采访.文中数次提到STL的基本思想.语言的特性.编程的一些根本问题等,非常精彩.这篇文章让我想去拜读下stepanov的大作& ...
 - LR11中webservice协议的性能测试应用
			
使用LR11对webservice协议的接口测试应用 脚本开发步骤:1.打开vuser generator,新建一个脚本,选择webservice协议:2.选择Manage Services(服务管理 ...
 - Netty面试题
			
1.BIO.NIO和AIO的区别? BIO:一个连接一个线程,客户端有连接请求时服务器端就需要启动一个线程进行处理.线程开销大. 伪异步IO:将请求连接放入线程池,一对多,但线程还是很宝贵的资源. N ...
 - interrupt 1 using 1
			
释疑:void Timer0() interrupt 1 using 1 Timer0 是函数名,随便取的 interrupt xx using y 跟在interrupt 后面的 ...