没有方法签名:java.lang.Integer.call()适用于参数类型:(java.lang.Integer)值:[1]

时间:2013-10-18 16:27:32

标签: for-loop groovy

以下groovy代码中内部循环的动态代码段2(i-1)出了什么问题?如果我将其替换为2ii+1或任何硬编码(例如6works fine

  1     class Algorithms {
  2      static def printTriangle(n){
  3           for(i in 1..n){
  4            if(i>1){
  5               for(j in 1..2(i-1)){ print 1 }
  6             } else { print 1 } } //end of inner loop
  7               println ""
  8           } //end of outer loop
  9       }

 24       static def main(args){

 26            printTriangles(4)
 27       }
 28   }

堆栈跟踪是

1
Caught: groovy.lang.MissingMethodException: No signature of method: java.lang.Integer.call() is applicable for argument types: (java.lang.Integer) values: [1]
Possible solutions: wait(), any(), abs(), wait(long), wait(long, int), each(groovy.lang.Closure)
groovy.lang.MissingMethodException: No signature of method: java.lang.Integer.call() is applicable for argument types: (java.lang.Integer) values: [1]
Possible solutions: wait(), any(), abs(), wait(long), wait(long, int), each(groovy.lang.Closure)
    at Algorithm.printTriangle(Algorithm.groovy:5)
    at Algorithm$printTriangle.callStatic(Unknown Source)
    at Algorithm.main(Algorithm.groovy:26)

1 个答案:

答案 0 :(得分:0)

Aghh,在代码工作之后,我没有做数学。

  for(j in 1..2*(i-1)){}