当前位置:网站首页>[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边栏推荐
- Basic grammar of interview (Part 1)
- Damn, window in ie open()
- Daily question brushing record (XIV)
- 如何開發引入小程序插件
- A number of ventilator giants' products have been recalled recently, and the ventilator market is still in incremental competition
- Countdown to 92 days, the strategy for the provincial preparation of the Blue Bridge Cup is coming~
- The Blue Bridge Cup web application development simulation competition is open for the first time! Contestants fast forward!
- Text组件新增内容通过tag_config设置前景色、背景色
- 【愚公系列】2022年7月 Go教学课程 004-Go代码注释
- Summary of concurrency control
猜你喜欢

Damn, window in ie open()

How to view Apache log4j 2 remote code execution vulnerability?

ICMP introduction

Nacos installation and service registration

2022软件测试工程师涨薪攻略,3年如何达到30K

Oracle triggers

Stored procedures and stored functions

Meituan dynamic thread pool practice ideas, open source

Blocking protocol for concurrency control

Livelocks and deadlocks of concurrency control
随机推荐
Livelocks and deadlocks of concurrency control
Interview questions for famous enterprises: Coins represent a given value
Analysis of the problem that the cookie value in PHP contains a plus sign (+) and becomes a space
Regular expressions and re Libraries
MySQL服务莫名宕机的解决方案
database mirroring
如何向mongoDB中添加新的字段附代码(全)
Stored procedures and stored functions
2022软件测试工程师涨薪攻略,3年如何达到30K
Calculation method of boundary IOU
装饰器学习01
Nacos 的安装与服务的注册
阿龙的感悟
Pl/sql basic syntax
Getting started with microservices (resttemplate, Eureka, Nacos, feign, gateway)
Win11缺少dll文件怎么办?Win11系统找不到dll文件修复方法
元宇宙中的三大“派系”
Interprocess communication in the "Chris Richardson microservice series" microservice architecture
Implementation technology of recovery
Search: Future Vision (moving sword)