4 Replies Latest reply on Nov 3, 2004 10:04 AM by chiba

    dispatch algorithm limitation

    tar

      We can read this at the end of the tutorial :

      The compiler does not correctly implement the Java method dispatch algorithm. The compiler may confuse if methods defined in a class have the same name but take different parameter lists.


      what it really mean ?

      I construct (with javassist) a new class with a new method which call a method 'foo(...)'. Two methods 'foo' are implemented in a other class which i defined in a classic way (with my IDE). One accept a Java.lang.Object as argument and the other accept a java.lang.String as argument.

      I understand that javassist might produce bytecode that call foo(String) instead of foo(Object) or foo(Object) instead of foo(String).

      Is it correct ? How can i recognize such case ? This limitation still exist in javassist v3 ?

      Thanks in advance.


        • 1. Re: dispatch algorithm limitation
          tar

          Sorry the layout may be a little confussing... here is the right layout.

          We can read this at the end of the tutorial :

          The compiler does not correctly implement the Java method dispatch algorithm. The compiler may confuse if methods defined in a class have the same name but take different parameter lists.


          what it really mean ?

          I construct (with javassist) a new class with a new method which call a method 'foo(...)'. Two methods 'foo' are implemented in a other class which i defined in a classic way (with my IDE). One accept a Java.lang.Object as argument and the other accept a java.lang.String as argument.

          I understand that javassist might produce bytecode that call foo(String) instead of foo(Object) or foo(Object) instead of foo(String).

          Is it correct ? How can i recognize such case ? This limitation still exist in javassist v3 ?

          Thanks in advance.

          • 2. Re: dispatch algorithm limitation
            chiba

            There still exits that bug. The compiler may produce a wrong call in
            the following case:

            class A {}
            class B extends A {}
            class C extends C {}

            class X {
            void foo(A a) { .. }
            void foo(B b) { .. }
            }

            If you call foo(new C()) on an instance of X, the compiler may produce
            a call to foo(A). But the compiler correctly compile foo((B)new C()).
            I haven't implemented a correct type inferencing algorithm yet.

            • 3. Re: dispatch algorithm limitation
              tar

              Thanks!

              I think you should include those few lines into the tutorial. It may help users.

              • 4. Re: dispatch algorithm limitation
                chiba

                Thanks, you're right.