Problem with overloaded method

Skip to first unread message


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();



    public static void main(String[] args) {

        Baz b = new Baz();




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?


Zhou Renjian

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

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
To post to this group, send email to
To view this discussion on the web visit
For more options, visit

Zhou Renjian

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
0 new messages