繁体   English   中英

捕获:groovy.lang.MissingMethodException:没有方法的签名

[英]Caught: groovy.lang.MissingMethodException: No signature of method

简单代码: ClosuresSyntax.groovy

{ -> item++ }
{ item -> item++ }

它导致异常:

Caught: groovy.lang.MissingMethodException: No signature of method:  
       com.lucaslee.groovy.syntax.ClosuresSyntax$_run_closure1.call()      is applicable for argument types:
(com.lucaslee.groovy.syntax.ClosuresSyntax$_run_closure2) values: 
    [com.lucaslee.groovy.syntax.ClosuresSyntax$_run_closure2@1534f01b]     

您的代码与(请注意括号)相同:

{ -> item++}({ item -> item++})

两个闭包的定义都是完全正确的。 问题在于实际上第一个闭包是通过第二个闭包作为参数来运行的。 这是完全一样的:

{ it -> it() } { println 1 }

由于无法在Closure对象上调用++ ,因此会抛出MissingMethodException 这将正常工作,例如:

{ item -> item()++ }{ 1 }

闭包{1}作为参数传递,被调用() ,结果递增++

要验证闭包定义正确,请运行:

def a = { -> item++ }
def b = { item -> item++ }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM