当前位置:网站首页>[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边栏推荐
- Some tutorials install the database on ubantu so as not to occupy computer memory?
- Business learning of mall commodity module
- [Chongqing Guangdong education] National Open University autumn 2018 0088-21t Insurance Introduction reference questions
- The Blue Bridge Cup web application development simulation competition is open for the first time! Contestants fast forward!
- Database tuning solution
- Bitbucket installation configuration
- Livelocks and deadlocks of concurrency control
- Interview questions for famous enterprises: Coins represent a given value
- 阿龙的感悟
- Oracle advanced query
猜你喜欢

MySQL服务莫名宕机的解决方案

Database tuning solution

Countdown to 92 days, the strategy for the provincial preparation of the Blue Bridge Cup is coming~

Technology cloud report: how many hurdles does the computing power network need to cross?

K210 learning notes (IV) k210 runs multiple models at the same time

Summary of concurrency control

Livelocks and deadlocks of concurrency control

A number of ventilator giants' products have been recalled recently, and the ventilator market is still in incremental competition

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

Nacos installation and service registration
随机推荐
Granularity of blocking of concurrency control
C language knowledge points link
Oracle views the data size of a table
Hcip day 16
FBO and RBO disappeared in webgpu
What changes has Web3 brought to the Internet?
Blocking protocol for concurrency control
CA certificate trampled pit
Oracle is sorted by creation time. If the creation time is empty, the record is placed last
How to use tensorflow2 for cat and dog classification and recognition
Calculation method of boundary IOU
Win11 runs CMD to prompt the solution of "the requested operation needs to be promoted"
119. Pascal‘s Triangle II. Sol
[Chongqing Guangdong education] National Open University autumn 2018 0088-21t Insurance Introduction reference questions
AD637 usage notes
Draw a red lantern with MATLAB
元宇宙中的三大“派系”
How can Bluetooth in notebook computer be used to connect headphones
Unique occurrence times of leetcode simple questions
MySQL服务莫名宕机的解决方案