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

📄 supermethod2bug.groovy

📁 大名鼎鼎的java动态脚本语言。已经通过了sun的认证
💻 GROOVY
字号:
/** * @version $Revision: 1.7 $ */ class SuperMethod2Bug extends GroovyTestCase {         void testBug() {    	def base = new SuperBase()    	def value = base.doSomething()    	assert value == "TestBase"    	    	    	base = new SuperDerived()    	value = base.doSomething()    	assert value == "TestDerivedTestBase"    }    void testBug2() {    	def base = new SuperBase()    	def value = base.foo(2)    	assert value == "TestBase2"    	    	    	base = new SuperDerived()    	value = base.foo(3)    	assert value == "TestDerived3TestBase3"    }    void testBug3() {    	def base = new SuperBase()    	def value = base.foo(2,3)    	assert value == "foo(x,y)Base2,3"    	    	    	base = new SuperDerived()    	value = base.foo(3,4)    	assert value == "foo(x,y)Derived3,4foo(x,y)Base3,4"    }    void testBug4() {    	def base = new SuperBase("Cheese")    	def value = base.name    	assert value == "Cheese"    	    	    	base = new SuperDerived("Cheese")    	value = base.name    	assert value == "CheeseDerived"    }        void testCallsToSuperMethodsReturningPrimitives(){       def base = new SuperBase("super cheese")       assert base.longMethod() == 1       assert base.intMethod() == 1       assert base.boolMethod() == true              base = new SuperDerived("derived super cheese")       assert base.longMethod() == 1       assert base.intMethod() == 1       assert base.boolMethod() == true           }}class SuperBase {    String name    SuperBase() {    }        SuperBase(String name) {        this.name = name    }        def doSomething() {    	"TestBase"    }    def foo(param) {    	"TestBase" + param    }        def foo(x, y) {    	"foo(x,y)Base" + x + "," + y    }        boolean boolMethod(){true}    long longMethod(){1l}    int intMethod(){1i}}class SuperDerived extends SuperBase {    	def calls = 0		SuperDerived() {	}		SuperDerived(String name) {	    super(name + "Derived")	}	    def doSomething() {    	/** @todo ++calls causes bug */    	//calls++    	/*    	calls = calls + 1    	assert calls < 3    	*/    	    	"TestDerived" + super.doSomething()    }	    def foo(param) {    	"TestDerived" + param + super.foo(param)    }	    def foo(x, y) {    	"foo(x,y)Derived" + x + "," + y + super.foo(x, y)    }        // we want to ensure that a call with super, which is directly added into     // bytecode without calling MetaClass does correct boxing    boolean booMethod(){super.boolMethod()}    int intMethod(){super.intMethod()}    long longMethod(){super.longMethod()}}

⌨️ 快捷键说明

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