We have spoken about adding support (in dynamic Groovy) for NullObject just like you suggest. I couldn't find it right now in a Jira or the current mailing lists. Maybe it was codehaus days.
The original thinking of NullObject was that it shouldn't normally appear in user code. But maybe it's fine in this case. Paul. On Fri, Jan 31, 2025 at 7:49 AM o...@ocs.cz <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