Hi there! Just a followup (of a message posted to the users maillist, quoted below). Meantime I've found that in the case with a single argument, as shown originally, I can use typeless (well, Object) argument and the method is selected all right, as it is with foo.
What seems quite weird though is that with another argument is stops working completely. I am posting now to the dev maillist, for this inconsistency stinks to me by a bug somewhere in the dispatcher code: === 1009 ocs /tmp> <q.groovy class Test { def foo(Collection foo) {} def foo(Map foo) {} def foo(foo) {println 'Sorta OK: '+foo.getClass()} def bar(Collection foo,List ll) {} def bar(Map foo,List ll) {} def bar(foo,List ll) {println 'Would be sorta OK if worked'} } def t=new Test() t.foo(null) // so far so good, prints out the class which does not work for argument, but... t.bar(null,[]) // ... what the?!? 1010 ocs /tmp> /usr/local/groovy-4.0.24/bin/groovy q Sorta OK: class org.codehaus.groovy.runtime.NullObject Caught: groovy.lang.GroovyRuntimeException: Ambiguous method overloading for method Test#bar. Cannot resolve which method to invoke for [null, class java.util.ArrayList] due to overlapping prototypes between: [interface java.util.Collection, interface java.util.List] [interface java.util.Map, interface java.util.List] === Thanks for any insight, OC > On 30. 1. 2025, at 22:48, o...@ocs.cz wrote: > > Hi there, > > is there a way to write a method with argument which would match null > specifically when called? This does not work: > > === > 1022 ocs /tmp> <q.groovy > class Test { > def foo(Collection foo) {} > def foo(Map foo) {} > def foo(org.codehaus.groovy.runtime.NullObject foo) {} > } > new Test().foo(null) > 1023 ocs /tmp> /usr/local/groovy-4.0.25/bin/groovy q > Caught: groovy.lang.GroovyRuntimeException: Ambiguous method overloading for > method Test#foo. > Cannot resolve which method to invoke for [null] due to overlapping > prototypes between: > [interface java.util.Collection] > [interface java.util.Map] > === > > Thanks! > OC