[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()
Planet p2 = new Planet()
Planet p3 = new Planet() //Planet.name = "Pluto" illegal
Planet.shape = "Circle" p1.name = "earth"
//p1.shape = "circle" p2.name = "jupiter"
//p2.shape = "circle" p3.name = "mars"
//p3.shape = "circle" log.info p1.name+" "+p1.shape
log.info p2.name+" "+p2.shape
log.info p3.name+" "+p3.shape p1 = p2
log.info "*************************************"
log.info p1.name+" "+p1.shape
log.info p2.name+" "+p2.shape
log.info p3.name+" "+p3.shape p1.name = "pluto"
log.info "*************************************"
log.info p1.name+" "+p1.shape //pluto
log.info p2.name+" "+p2.shape //pluto
log.info p3.name+" "+p3.shape class Planet{
// variables and functions
def name // non static variable
def static shape // static variable
}
运行结果:
Tue Oct 06 16:27:27 CST 2015:INFO:starting
Tue Oct 06 16:27:27 CST 2015:INFO:earth Circle
Tue Oct 06 16:27:27 CST 2015:INFO:jupiter Circle
Tue Oct 06 16:27:27 CST 2015:INFO:mars Circle
Tue Oct 06 16:27:27 CST 2015:INFO:*************************************
Tue Oct 06 16:27:27 CST 2015:INFO:jupiter Circle
Tue Oct 06 16:27:27 CST 2015:INFO:jupiter Circle
Tue Oct 06 16:27:27 CST 2015:INFO:mars Circle
Tue Oct 06 16:27:27 CST 2015:INFO:*************************************
Tue Oct 06 16:27:27 CST 2015:INFO:pluto Circle
Tue Oct 06 16:27:27 CST 2015:INFO:pluto Circle
Tue Oct 06 16:27:27 CST 2015:INFO:mars Circle
[Training Video - 3] [Groovy in Detail] Non-static and Static variables, objects and object referances的更多相关文章
- [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() ...
- [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" ...
随机推荐
- Java-Runoob-高级教程:Java 文档注释
ylbtech-Java-Runoob-高级教程:Java 文档注释 1.返回顶部 1. Java 文档注释 Java 支持三种注释方式.前两种分别是 // 和 /* */,第三种被称作说明注释,它以 ...
- python学习(二十七) 元组
# 元组是不可变的,不能改变元素的值,也不能增加.减少元素my_tuple = (1, 2, 3, 3)print(my_tuple) # 查找元素位置print(my_tuple.index(2)) ...
- git 怎么上传文件到github上
1.安装git sudo apt-get install git 2.配置全局变量 git config --global user.name langhunm git co ...
- ubuntu下用expect实现密码自动输入
每次笔记本一开机启动,总会连用不着且碍事的触摸板也一块启动.便想写个脚本,让电脑启动时关闭触摸板.(当然,我想更好的办法是,修改系统启动时的加载模块,让触摸板不自动加载,但是目前还不知道用这种方法怎么 ...
- 排除maven jar冲突 maven tomcat插件启动报错 filter转换异常
最近在搞一个ssm+shiro的整合 用的maven tomcat插件 启动的时候报错,提示 maven org.springframework.web.filter.CharacterEncodin ...
- mysql 理解索引,添加索引,使用索引(哪些情况会导致索引失效)
索引用于快速找出在某个列中有一特定值的行.不使用索引,MySQL必须从第1条记录开始然后读完整个表直到找出相关的行,还需要考虑每次读入数据页的IO开销.而如果采取索引,则可以根据索引指向的页以及记录在 ...
- 在C#中控制ListBox某一行的字体颜色
例1 private void Form1_Load(object sender, EventArgs e) { listBox1.Items.Add("红色"); listBox ...
- Java设计模式学习06——静态代理与动态代理(转)
原地址:http://blog.csdn.net/xu__cg/article/details/52970885 一.代理模式 为某个对象提供一个代理,从而控制这个代理的访问.代理类和委托类具有共同的 ...
- ConcurrentHashMap源码分析(JDK8版本<转载>)
注:本文源码是JDK8的版本,与之前的版本有较大差异 转载地址:http://blog.csdn.net/u010723709/article/details/48007881 ConcurrentH ...
- GitHub个人使用入门
今天突然想起来了github 于是开始了入门之旅 如果你用过svn 那么你用起来感觉入门比较快的(至少我是这么感觉的)和在svn服务器上建项目的流程很像 每次修改代码之后提交的过程是: add, co ...