[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" ...
随机推荐
- 初学FPGA一些建议
数字电路: 这是大学里的基本课程 ,涵盖了一般数字电路的组合电路.时序电路.寄存器传输.储存器以及可编程逻辑电路(FPGA 就是其中一种),还有比较好的添加了计算机的指令集结构.处理器设计等计算机方面 ...
- java代码---charAt()和toCharry()的用法
总结:charAt()是返回字符型,把字符串拆分成某个字符,返回指定位置的字符.可以把字符串看成char型数组 package com.sads; ///输出一个大写英文字母的 public clas ...
- 【学步者日记】实现破碎效果 Fracturing & Destruction 插件使用
全文见原始链接:http://note.youdao.com/noteshare?id=ef5ef90b71da4e960e5bc0da4f3f17ec 下面是预览 示例工程链接:https://pa ...
- Zabbix 添加 WEB 监控
添加 WEB Monitorings Web Monitoring是用来监控web程序的,可以监控到web程序的下载速度.返回码及响应时间,还支持把一组连续的web动作作为一个整体来监控. 下面我们以 ...
- MySQL 5.7.18 主从复制 Error1205
从库报 error 1205 1.mysql报错信息 [root@slave2(35.102) ~]# mysql -uroot -p Enter password: Welcome to the M ...
- 模拟admin组件自己开发stark组件之创建篇
admin组件 admin组件为我们提供了针对django管理页面 我们先简短来看下django的admin组件的启动流程,注册流程,url匹配过程 启动注册 1. 扫描所有应用下的注册了应用中的ad ...
- canvas之画矩形
<canvas id="canvas" width="600" height="500" style="background ...
- length length()
数组长度 length String 长度 length()
- ubuntu apt-get常用命令
apt-cache search package 搜索包apt-cache show package 获取包的相关信息,如说明.大小.版本等sudo apt-get install package 安 ...
- 3.docker学习之docker与虚拟化
虚拟化技术是一个总称,是一系列实现虚拟技术的统称.从广义上来说,虚拟化技术包括了虚拟机技术和容器技术, 所谓虚拟化技术最大的特点就是将一个真实的机器进行虚拟地分割,然后分割出来的部分可以独立使用 ...