[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.info b3.name
Bank b4 = new Bank("B",1200,"X1")
Bank b5 = new Bank("C",1300,"X2")
log.info b5.minbalance

class Bank{
	def static log
	def name
	def minbalance
	def city

	public Bank(){      // no return type, same name with class name
		log.info "inside constructor"
	}

//	public Bank(bankName,bankMinBal,bankCity){
//		name = bankName
//		minbalance = bankMinBal
//		city = bankCity
//	}

	public Bank(name,minbalance,city){
		this.name = name
		this.minbalance = minbalance
		this.city = city
	}
}

Run result:

Tue Oct 06 19:51:29 CST 2015:INFO:inside constructor
Tue Oct 06 19:51:29 CST 2015:INFO:inside constructor
Tue Oct 06 19:51:29 CST 2015:INFO:A
Tue Oct 06 19:51:29 CST 2015:INFO:1300
时间: 2025-01-16 16:23:44

[Training Video - 4] [Groovy] Constructors in groovy, this keyword的相关文章

Error:Cannot compile Groovy files: no Groovy library is defined for module 'xxxx' 错误处理

出现 Error:Cannot compile Groovy files: no Groovy library is defined for module 'xxxx' 只要在 project structure 中的modules中左上角的 + 号,然后找到groovy添加即可! 具体可参考: http://stackoverflow.com/questions/43450683/errorcannot-compile-groovy-files-no-groovy-library-is-def

[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

[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 - 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 regex groups(groovy正则表达式组)

先看一个java正则表达式的例子. import java.util.regex.Matcher; import java.util.regex.Pattern; public class TestMatch { public static void main(String[] args) { Pattern pattern = Pattern.compile("G.*"); Matcher matcher = pattern.matcher("Groovy");

[Training Video - 7] [Database connection] Part 1

try, catch and finally in db connection Forming groovy connection string and obtaining Connection Object Firing Select Query and obtaining results Foreach and rows functions Finding number of rows in result import groovy.sql.Sql // obtain the connect

推荐一本学习Groovy的书籍Groovy程序设计!

有朋友公司在用groovy开发,于是推荐我学习一下,搜到了这本书: 花了一个月时间读完了这本书!写的很棒,几乎没有废话,全书都是很重要的知识点和很好的讲解,确实像封面说的那样,使用的好可以提高开发效率 唯一不足的可能是版本太旧了,而且java也在高速进步,12已经发布了,其实java并没有书里说的那么不堪,哈哈,java的lambda就很牛逼了, 虽然groovy的闭包更牛逼,想学习Groovy的童鞋,这本书一定要看,知识点很多! java知识分享网就可以下载高清pdf! 另外,这是我读书的时候