-
1. Re: Overriding methods outside EJB
adrian.brock Feb 1, 2002 1:00 PM (in response to jameswilson)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
jameswilson Feb 4, 2002 4:02 AM (in response to jameswilson)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 Feb 4, 2002 6:18 AM (in response to jameswilson)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
jameswilson Feb 4, 2002 9:05 AM (in response to jameswilson)OK thanks, I was hoping it would do the
System.out.println(shape3.intersects(shape2));
one as well.
Thanks for your help,
James.