[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" ...
随机推荐
- elasticsearch 5.0 获取 TransportClient 操作客户端java API
本文转载自:http://blog.csdn.net/likui1314159/article/details/53233881 elasticsearch 5.0 获取 TransportClien ...
- python is 和 == 的区别
一.is 和 == 的区别 == 比较 比较的俩边的值 is 比较 比较的是内存地址 id() 二.小数据池 数字小数据池的范围 -5 ~ 256 字符串中如果有特殊字符他们的内存地址就不一样 字符串 ...
- android 手机UDP 接受不到数据
一.有的手机不能直接接收UDP包,可能是手机厂商在定制Rom的时候把这个功能给关掉了. 1.可先在oncreate()方法里面实例化一个WifiManager.MulticastLock 对象lock ...
- 设置VS以管理员身份运行
以vs2013为例 vs右键属性 ----- 找到目标位置如下 "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\ ...
- JNI的一个简单实例
本例子使用的操作系统MacOS, 64位JVM. JNI编写的几个步骤如下: 编写Java代码,并注明native方法: public class HelloJni { public native v ...
- Java测试用例简介
最近需要向组内其他成员普及一下关于Java测试用例的相关知识,特在此进行一下简单的学习和总结. JUnit简介 JUnit是一个开源的Java单元测试框架,JUnit4对原有的JUnit框架进行了大幅 ...
- Linux系统命令与脚本开发
系统命令 # cat EFO cat >> file << EOF neirong EOF # 清空 >file 清空文件 [root@Poppy conf]# sed ...
- 关于select的一个死循环
#include <stdio.h> #include <sys/types.h> #include <unistd.h> #include <sys/sel ...
- 【HDU】2222 Keywords Search(AC自动机)
题目 传送门:QWQ 分析 $ AC $自动机模板,黈力的码风真的棒极了,这是我抄他的. 还有 题号不错 代码 #include <cstdio> #include <cstring ...
- ProducerConsumerQueue
folly/ProducerConsumerQueue.h The folly::ProducerConsumerQueue class is a one-producer one-consumer ...