jastrachan | 18 Nov 08:40 2004
Picon

Re: Static dispatch and call semantics

On 17 Nov 2004, at 18:35, John Wilson wrote:
> Another question:
>
> Giver the Java class
>
> class C extends GroovyObjectSupport {
> 	void f(Integer i) {
> 	}
>
> 	void f(String s) {
> 	}
> }
>
> how is the following Groovy handled?
>
> C c = new C()
> any a = 1
> c.f(a)
> a = 'hello'
> c.f(a)
>
> It would appear that the calls of f on c must be implemented using 
> dynamic dispatch.

Not necessarily. What you're demonstrating is that to maintain 
semantics with dynamic dispatch, we need to implement proper 
multi-methods. i.e. if there are multiple f() methods we need to choose 
the right one at runtime based on the type of the parameters. We can 
still do this efficiently in static java bytecode.

James
-------
http://radio.weblogs.com/0112098/


Gmane