4 Replies Latest reply on Feb 4, 2002 9:05 AM by James

    Overriding methods outside EJB

    James Newbie

      I have successfully created a few beans and deployed them through Jboss. Some of the beans inherit off of each other.
      However when I am outside the bean the Jboss container does not appear to be allowing me to override methods using the beans that I have created.
      e.g. I have a Resource bean and a Message bean. The Message bean inherits from the Resource bean. Now in a JSP tag I have two methods getAttribute(Resource) and getAttribute(Message) - however unless I explicitly cast my resource to a message, getAttribute(Resource) is always called.
      Is this a Jboss feature because of the proxy classes? or does anybody have a solution,

      Thanks,

      James

        • 1. Re: Overriding methods outside EJB
          Adrian Brock Master

          Hi,

          This is not overriding, this is Multi-Methods.
          Java does not support it. Nor does C++

          You'll have to make the Message.get() method take a Resource
          and cast it to a Message.

          Regards,
          Adrian

          • 2. Re: Overriding methods outside EJB
            James Newbie

            Sorry, I did not explain that too well. I meant overloading - not overriding.

            We have two Interfaces that inherit off each other (Message is a child of Resource). We are passing these to class outside of JBOSS into a function called getAttribute. We have overloaded this function so that it behaves differently for each type.

            e.g. void getAttribute(Message message){}
            and void getAttribute(Resource resource){}

            I think this would work in Java normally. However when dealing with JBOSS proxy classes this does not work.

            • 3. Re: Overriding methods outside EJB
              Adrian Brock Master

              No this is still multi methods.

              The classic example is shapes:

              [pre]
              public class Shape
              {
              public boolean intersects(Shape other)
              {
              //blah
              }
              }

              public class Circle
              extends Shape
              {
              public boolean intersects(Circle other)
              {
              // blah
              }
              }

              public static void test()
              {
              Shape shape1 = new Shape();
              Shape shape2 = new Circle();
              Circle shape3 = new Circle();
              System.out.println(shape1.intersects(shape1));
              System.out.println(shape1.intersects(shape2));
              System.out.println(shape1.intersects(shape3));
              System.out.println(shape2.intersects(shape1));
              System.out.println(shape2.intersects(shape2));
              System.out.println(shape2.intersects(shape3));
              System.out.println(shape3.intersects(shape1));
              System.out.println(shape3.intersects(shape2));
              System.out.println(shape3.intersects(shape3));
              }
              [/pre]

              Only the last invocation does
              Circle.intersects(Circle)
              the others do
              Shape.intersects(Shape)

              Overloading allows you to have both
              Circle.intersects(Shape)
              Circle.intersects(Circle)
              but it does not take part in polymorphism :-(

              Regards,
              Adrian

              • 4. Re: Overriding methods outside EJB
                James Newbie

                OK thanks, I was hoping it would do the
                System.out.println(shape3.intersects(shape2));
                one as well.

                Thanks for your help,

                James.