Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Well, I'm getting MissingMethodException even after inserting a method into a metaclass. It's strange that its says there's no signature applicable for a String, but there's for java.lang.Object Some obs:

    • yeah, the List<Class> classes that I'm iterating contains the class I'm trying to use
    • please don't suggest me to use @Log4j or any other, it's not working with any method I try to insert (even though I can manipulate the same class fields with reflections)
    • as I said, the stackstrace says that there isn't signature (java.lang.String) but there's to (java.lang.Object)
        classes.each { clazz ->
            clazz.metaClass.log = { instance.simpleLogger.log(it) }
            clazz.metaClass.debug = { instance.simpleLogger.debug(it) }
    @Override
    void enable() {
        debug("eae meu bom")
    }
groovy.lang.MissingMethodException: No signature of method: com.dont.testplugin.Terminal.debug() is applicable for argument types: (java.lang.String) values: [eae meu bom]
Possible solutions: debug(), debug(java.lang.Object), getAt(java.lang.String), log(), dump(), log(java.lang.Object)
        at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:56) ~[?:?]
        at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:78) ~[?:?]
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:49) ~[?:?]
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133) ~[?:?]
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:141) ~[?:?]
question from:https://stackoverflow.com/questions/65866095/groovy-no-signature-of-method-after-inserting-a-method

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
562 views
Welcome To Ask or Share your Answers For Others

1 Answer

Echoing @daggett here, with the assumption that you are calling the debug method from groovy (and not java) and that the place you are calling it from is not annotated with something like @CompileStatic I would have expected that to work as well.

The following code:

class Foo {}
Foo.class.metaClass.debug = { println("debug: $it") }

def f = new Foo()
f.debug("eae meu bom")

when executed prints:

─? groovy solution.groovy
debug: eae meu bom

(Groovy Version: 3.0.6 JVM: 11.0.9.1)

I think we need more context to get you relevant answers.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...