You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@groovy.apache.org by "ocs@ocs.cz" <oc...@ocs.cz> on 2023/10/13 14:33:27 UTC

overriding a method for a null argument

Hi there,

isn't this a bug in the method dispatcher? (Works precisely same way with explicit .plus(...)) I would assume "null: null" to be printed out by the last command:

===
2016 ocs /tmp> <q.groovy                            
class Foo {
 static main(args) {
    ExpandoMetaClass.enableGlobally()
    Integer.metaClass.plus<<{ Thread foo -> 'thread' } // just to make sure adding methods works OK
    Integer.metaClass.plus<<{ org.codehaus.groovy.runtime.NullObject foo -> 'null' } // does not here, tho
    println "thread: ${7+Thread.currentThread()}"
    println "null: ${7+null}"
  }
}
2017 ocs /tmp> /usr/local/groovy-4.0.5/bin/groovy q
thread: thread
Caught: groovy.lang.GroovyRuntimeException: Ambiguous method overloading for method java.lang.Integer#plus.
Cannot resolve which method to invoke for [null] due to overlapping prototypes between:
	[class java.lang.Character]
	[class java.lang.String]
	[class java.lang.Number]
	[class java.lang.Thread]
...
===

Thanks,
OC