当前位置:网站首页>[error record] groovy function parameter dynamic type error (guess: groovy.lang.missingmethodexception: no signature of method)
[error record] groovy function parameter dynamic type error (guess: groovy.lang.missingmethodexception: no signature of method)
2022-07-05 22:18:00 【Programmer community】
One 、 Error message
Definition Groovy function ,
void fun(object) {
object.hello()}
If the incoming Instance object in , No definition hello Method , This will result in the following error reports ;
Error code :
class Student {
def hello(){
println "Hello Student" }}class Worker {
def hello(){
println "Hello Worker" }}class Farmer {
}void fun(object) {
object.hello()}fun(new Student())fun(new Worker())// The following usage will report // Caught: groovy.lang.MissingMethodException abnormal fun(new Farmer())
Error message :
Caught: groovy.lang.MissingMethodException: No signature of method: Farmer.hello() is applicable for argument types: () values: []Possible solutions: sleep(long), sleep(long, groovy.lang.Closure), getAt(java.lang.String), each(groovy.lang.Closure), split(groovy.lang.Closure), wait()groovy.lang.MissingMethodException: No signature of method: Farmer.hello() is applicable for argument types: () values: []Possible solutions: sleep(long), sleep(long, groovy.lang.Closure), getAt(java.lang.String), each(groovy.lang.Closure), split(groovy.lang.Closure), wait() at Worker$hello.call(Unknown Source) at Groovy.fun(Groovy.groovy:20) at Groovy$fun.callCurrent(Unknown Source) at Groovy.run(Groovy.groovy:28)
Two 、 Solution
have access to respondsTo Method , Determine whether hello function ;
void fun(object) {
if (object.respondsTo("hello")) {
object.hello() }}
Also can reference 【Groovy】Groovy Dynamic language features ( Groovy Automatic type inference of function arguments in | Precautions for function dynamic parameters ) Blog , At the expense of dynamic characteristics , Limit it to static languages , Then the above runtime error will not occur ;
The complete code is as follows :
class Student {
def hello(){
println "Hello Student" }}class Worker {
def hello(){
println "Hello Worker" }}class Farmer {
}void fun(object) {
if (object.respondsTo("hello")) {
object.hello() }}fun(new Student())fun(new Worker())// The following usage will report // Caught: groovy.lang.MissingMethodException abnormal fun(new Farmer())
Execution results :
Hello StudentHello Worker
边栏推荐
- MySQL服务莫名宕机的解决方案
- Oracle triggers
- 【愚公系列】2022年7月 Go教学课程 003-IDE的安装和基本使用
- Technology cloud report won the special contribution award for the 10th anniversary of 2013-2022 of the "cloud Ding Award" of the global cloud computing conference
- Official clarification statement of Jihu company
- 70. Climbing Stairs. Sol
- 阿龙的感悟
- Shelved in TortoiseSVN- Shelve in TortoiseSVN?
- 了解 Android Kotlin 中 DataStore 的基本概念以及为什么应该停止在 Android 中使用 SharedPreferences
- Some tutorials install the database on ubantu so as not to occupy computer memory?
猜你喜欢
2022-07-05: given an array, you want to query the maximum value in any range at any time. If it is only established according to the initial array and has not been modified in the future, the RMQ meth
Calculation method of boundary IOU
Getting started with microservices (resttemplate, Eureka, Nacos, feign, gateway)
Blocking protocol for concurrency control
What about data leakage? " Watson k'7 moves to eliminate security threats
The difference between MVVM and MVC
A trip to Suzhou during the Dragon Boat Festival holiday
Three "factions" in the metauniverse
[Yugong series] go teaching course in July 2022 004 go code Notes
Server optimization of performance tuning methodology
随机推荐
数博会精彩回顾 | 彰显科研实力,中创算力荣获数字化影响力企业奖
Index optimization of performance tuning methodology
854. String BFS with similarity K
Sentinel production environment practice (I)
FBO and RBO disappeared in webgpu
Implementing Lmax disruptor queue from scratch (IV) principle analysis of multithreaded producer multiproducersequencer
The difference between MVVM and MVC
微服务链路风险分析
极狐公司官方澄清声明
数据泄露怎么办?'华生·K'7招消灭安全威胁
Sub total of Pico development
Stored procedures and stored functions
2022-07-05:给定一个数组,想随时查询任何范围上的最大值。 如果只是根据初始数组建立、并且以后没有修改, 那么RMQ方法比线段树方法好实现,时间复杂度O(N*logN),额外空间复杂度O(N*
FBO and RBO disappeared in webgpu
A trip to Suzhou during the Dragon Boat Festival holiday
Matlab draws a cute fat doll
Serializability of concurrent scheduling
Platform bus
Kubernetes Administrator certification (CKA) exam notes (IV)
Lightweight dynamic monitorable thread pool based on configuration center - dynamictp