returntest.groovy
来自「大名鼎鼎的java动态脚本语言。已经通过了sun的认证」· GROOVY 代码 · 共 69 行
GROOVY
69 行
/** * Tests the use of returns in Groovy * * @author <a href="mailto:james@coredevelopers.net">James Strachan</a> * @version $Revision: 1.8 $ */class ReturnTest extends GroovyTestCase { void testIntegerReturnValues() { def value = foo(5) assert value == 10 } void testBooleanReturnValues() { def value = bar(6) assert value } def foo(x) { return ( x * 2 ) } def bar(x) { return x > 5 } void testVoidReturn() { explicitVoidReturn() implicitVoidReturn() explicitVoidReturnWithoutFinalReturn() implicitVoidReturnWithoutFinalReturn() } void explicitVoidReturn() { return } def implicitVoidReturn() { return } void explicitVoidReturnWithoutFinalReturn() { def x = 4; if (x == 3) { return; } else { try { x = 3; return; } finally { //do nothing } } } def implicitVoidReturnWithoutFinalReturn() { def x = 4; if (x == 3) { return; } else { try { x = 3; return; } finally { //do nothing } } } }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?