John Wilson schrieb:
> On Dec 7, 2007 12:52 PM, Jochen Theodorou <[EMAIL PROTECTED]> wrote:
>> John Wilson schrieb:
>> [...]
>>> Groovy has this as a potential issue because it also supports optional
>>> typing.
>> All that follows is a response to this and specific to Groovy:
>
>
> Actually I think the issue applies to any language which allows Java
> classes to be subclassed, supports untyped (or dynamically typed, if
> you prefer) parameters and generates class files.
>
> Consider the Java classes C and D
>
> class C {
> public Object foo(C c) {....
>
> class D extends C {
> public Object foo(Object d) {....
>
> now in my arbitrary dynamic language I do
>
> class E extends C {
> def foo(e) {....
>
> elsewhere in another class written in my arbitrary dynamic language I write
>
> def d = new D()
> def e = new E()
>
> d.foo(d)
> e.foo(e)
>
> If the dynamic language attempts to implement the Java method
> selection mechanism at runtime then d.foo(d) will call the method foo
> on C.
ok, let us go one step back.. static/dynamic typing have sometimes no
clear definition. In Groovy we say dynamic typing = the runtime type
will be used, static typing = the variable will have no incompatible
type at runtime. In this sense doing "def d" in Groovy means that for d
no type will be ensured, but for a call the dynamic type will still be
used. Since we can not freely choose our classes in Groovy the type "no
type" is equal to Object, and that is no problem with the static typing
part, because all objects are at runtime at last of type Object. So in
Groovy "def d" is totally equal to "Object d". With this in mind the
logic you described above makes perfect sense.
> If the runtime cannot distinguish between a method with an Object
> parameter and one with a dynamically typed parameter then e.foo(e)
> will also call the method on C.
see above, in Groovy there is no need to do this. The reason you want to
do this is because
[...]
> So, in Ng, e.foo(e) calls the method on E.
if you say E#foo overwrites all older foo methods with the same number
of parameters, then your problem is solved, or not?
> Note *none* of the above require the dynamic language to support
> optional static typing so I think it's an issue for Jython and JRuby
> too.
I spoke for Groovy and in Groovy it is no issue as soon as you
understand, that def is more or less a alias for Object. AS for JRuby
and Jython, I guess the people from these projects can answer this much
better than I could ;)
bye blackdrag
--
Jochen "blackdrag" Theodorou
The Groovy Project Tech Lead (http://groovy.codehaus.org)
http://blackdragsview.blogspot.com/
http://www.g2one.com/
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "JVM
Languages" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/jvm-languages?hl=en
-~----------~----~----~----~------~----~------~--~---