⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 methodparameteraccesswithinclosuretest.groovy

📁 大名鼎鼎的java动态脚本语言。已经通过了sun的认证
💻 GROOVY
字号:
/** * To test access to method scoped variable within closure *  * @author <a href="mailto:jeremy.rayner@bigfoot.com">Jeremy Rayner</a> * @version $Revision: 1.3 $ */class MethodParameterAccessWithinClosureTest extends GroovyTestCase {     def cheese    def shop           void setUp() {        cheese = null        shop = ["wensleydale"]    }                  void testSimpleMethodParameterAccess() {         assert "wensleydale" == vendor1("wensleydale")     }    void testMethodParameterWithDifferentNameToPropertyUsingClosure() {        assert "wensleydale" == vendor2("wensleydale")    }    void testMethodParameterWithSameNameAsPropertyUsingClosure() {        //@todo fails in 1.0b6           println vendor3("wensleydale")        // assert "wensleydale" == vendor3("wensleydale")    }        private String vendor1(cheese) {        cheese    }        private String vendor2(aCheese) {        shop.find() {it == aCheese}    }        private String vendor3(cheese) {        // problem is that cheese here refers to def 'cheese'        // and not the method parameter 'cheese'        println "shop = $shop"        println "cheese = $cheese"        def a  = shop.find() {println (it == cheese)}        println ([1, 2, 3].find() {it == 2})        println (["wensleydale"].find() {it == "wensleydale"})        println (shop.find() {it == "wensleydale"})        println (shop.find() {it == cheese})        println "a = $a"    }} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -