Groovy动态语言 运行在JVM中的动态语言 可以方便的处理业务逻辑变化大的业务

源代码在线查看: closurevariablebug.groovy

软件大小: 1644 K
上传用户: maple_78
关键词: Groovy JVM 动态语言 运行
下载地址: 免注册下载 普通下载 VIP

相关代码

				/**
				 * @version $Revision: 2284 $
				 */
				class ClosureVariableBug extends GroovyTestCase {
				    
				    void testClosurePassingBug() {
				        def count = 0
				        def closure = { assert count == it }
				        closure(0)
				        
				        count = 1
				        closure(1)
				    }
				    
				    void testPassingClosureAsNamedParameter() {
				        def x = 123
				        
				        def foo = new Expando(a:{x}, b:456)
				    
				        assert foo.a != null
				        
				        println "Foo has a = ${foo.a}"
				        
				        def value = foo.a()
				        assert value == 123
				    }
				    
				    void testBug() {
				        def value = callClosure([1, 2])
				        assert value == 2
				    }
				    
				    protected Integer callClosure(collection) {
				        Integer x
				        /** @todo
				        Integer x = 0
				        */
				        collection.each { x = it }
				        return x
				    }
				}			

相关资源