简体   繁体   English

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

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

Simple code: ClosuresSyntax.groovy 简单代码: ClosuresSyntax.groovy

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

it cause an exception: 它导致异常:

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]     

Your code is the same as (note the parentheses): 您的代码与(请注意括号)相同:

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

The definition of both closures is fully correct. 两个闭包的定义都是完全正确的。 The problem is that in fact the first closure is run with the second one passed as an argument. 问题在于实际上第一个闭包是通过第二个闭包作为参数来运行的。 This is exactly the same: 这是完全一样的:

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

Since you can't invoke ++ on a Closure object MissingMethodException is thrown. 由于无法在Closure对象上调用++ ,因此会抛出MissingMethodException This will work correctly eg: 这将正常工作,例如:

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

A closure {1} is passed as an argument, invoked () and a result is incremented ++ . 闭包{1}作为参数传递,被调用() ,结果递增++

To verify that closures definitions are correct, run: 要验证闭包定义正确,请运行:

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

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

相关问题 Groovy:groovy.lang.MissingMethodException:方法未签名 - Groovy : groovy.lang.MissingMethodException: No signature of method jenkinspipeline groovy.lang.MissingMethodException:没有方法签名 - jenkinspipeline groovy.lang.MissingMethodException: No signature of method groovy.lang.MissingMethodException:没有方法解析的签名 - groovy.lang.MissingMethodException: No signature of method resolution groovy.lang.MissingMethodException:没有方法的签名: - groovy.lang.MissingMethodException: No signature of method: groovy.lang.MissingMethodException:没有方法签名 - groovy.lang.MissingMethodException: No signature of method 错误:groovy.lang.MissingMethodException:没有方法签名 - ERROR:groovy.lang.MissingMethodException: No signature of method groovy.lang.MissingMethodException:肥皂中没有方法--groovy脚本的签名 - groovy.lang.MissingMethodException:No signature of method --groovy script in soap groovy.lang.MissingMethodException:groovy脚本中没有方法签名 - groovy.lang.MissingMethodException: No signature of method in groovy script groovy.lang.MissingMethodException:方法的无签名:在詹金斯构建流程的groovy中 - groovy.lang.MissingMethodException: No signature of method: in groovy on jenkins buildflow Jenkins groovy.lang.MissingMethodException:没有方法签名:catchError() - Jenkins groovy.lang.MissingMethodException: No signature of method: catchError()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM