Problem with overloaded method

20 views
Skip to first unread message

Udo

unread,
Apr 2, 2016, 2:19:00 PM4/2/16
to Java2Script
We have this class:

public class Main {

    public interface Foo {};

    public static class Bar {};

    public static class Baz extends Bar implements Foo {};

    

    public static class Qux {

        void f(Foo arg){ System.out.println("f(Foo) called"); }

        void f(Bar arg){ System.out.println("f(Bar) called"); }

    }

    

    public static void g(Foo foo) {

        Qux q = new Qux();

        q.f(foo);

    }


    public static void main(String[] args) {

        Baz b = new Baz();

        g(b);

    }


}


Running this class' main function in Java prints out:

f(Foo) called


Running it in Java2Script outputs:

f(Bar) called


It looks like the call q.f(foo) in method g select the wrong implementation of f: it should call the f(Foo) overload, as Foo is the type called with. But instead it chooses f(Bar). 

I am not sure if this is a bug or a limitation of Java2Script.

Any comments?


Udo






Zhou Renjian

unread,
Apr 3, 2016, 11:02:56 PM4/3/16
to Java2Script
It should be a bug of Java2Script, which should be fixed later.

Passing null as a argument should get expected result. 

Null is specially casted. So this bug should be fixed as similar:In compiler: add extra class casting to force using given type if necessary. Then in JavaScript class simulator, add similar code of Clazz.CastedNull


Regards,
Zhou Renjian

--
You received this message because you are subscribed to the Google Groups "Java2Script" group.
To unsubscribe from this group and stop receiving emails from it, send an email to java2script...@googlegroups.com.
To post to this group, send email to java2...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/java2script/e607f87e-9b8f-4f85-a92d-bfeadf84c094%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Zhou Renjian

unread,
Jun 23, 2016, 3:50:22 PM6/23/16
to Java2Script
Fixed in latest Java2Script build for Eclipse 4.5 and 4.6.
Reply all
Reply to author
Forward
0 new messages