formalparametertest.groovy

来自「Groovy动态语言 运行在JVM中的动态语言 可以方便的处理业务逻辑变化大的业」· GROOVY 代码 · 共 29 行

GROOVY
29
字号
package gls.ch08.s04

import gls.scope.CompilableTestSupport

/**
* a formal parameter is a parameter to a method, this parameter must work
* as any local variable. But we generally do boxing on local variables, which
* is not possible for formal parameters. The type is givven through the
* method signature.
*/
class FormalParameterTest extends CompilableTestSupport{
    
  void testPrimitiveParameterAssignment(){
    // test int and long as they have different lengths on in the bytecode
    assert intMethod(1i,2i) == 2i
    assert longMethod(1l,2l) == 2l
    
  }
  
  int intMethod(int i, int j) {
    i=j
    return i
  }
  
  long longMethod(long i, long j) {
    i=j
    return i
  }
}

⌨️ 快捷键说明

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