overriding a method for a null argument

"[email protected]" <[email protected]>
Newsgroups gmane.comp.lang.groovy.user
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.