groovy之基础篇

quzhongwei 2010-07-19

package fist
class HelloWorld {
 
 static main(args) {
  println("===========HelloWorld "+new java.util.Date());
  System.out.println("HI GROOVY");
  
  def var="YES";
  println var;
  println var.class;
  var=1000;
  println var.class;
  
  println("MAP------------------"); 
  def map=['name':'VerRan','age':'25'];
  println map['name'];
  println map.age;
  map.wife='dove';
  println map.wife;
  
  map.each({println it});
  map.each({key,value->println "$key:$value"});
  
  println("Collect集合------------------");
  def collect=['a','b','c'];
  println collect[1];
  println collect.size;
  println collect[-2];
  
  println("闭包------------------");
  def say={world->
   println "come on 闭包,$world";
   }
  say("HIIIIIIII");
 }
}
class Sencod extends GroovyTestCase {
	public void test(){
		
		def animals=['dog','maomi','caw','cat'];
		assert animals.size()==4;
		assert animals.get(1)=="maomi";
		
		def add={
			a,b-> return a+b;
			}
		def c=add.call(1,2);
		assert c==3;
		
		def values=animals.find{it.size()>3};
		assert values=="maomi";
		
		println animals.every({it.size()>3});
		println animals.any({it.size()>3});
		println animals.min();
		println animals.max();
		println animals.join (";");
		}
}

相关推荐