class base{}
class childA extends base{}
class childB extends base{}
I have two functions (overloaded) like this:
function(childA,childA){}
function(childA,childB){}
//main program
base a = new childA();
base b = new childB();
function(a,b);
function(a,a); //problem
The function calls won't compile obviously.
But is there a way to get the same effect without complicating the code too much or type checking each time the functions are called.
Note: The overloaded functions are independent of the classes. The classes are just data structures, I would rather not have any interdependent code in them.
PS. I went through quite a few topics covering similar problems, but they don't seem to address the problems mentioned above. Sorry if I missed something, (newbie, first post etc :)).
Edit :
Seems my example was a bit vague, I just wanted to understand the concept in general instead of just a solution to the immediate problem. Seems strange that the above code doesn't work, would have been a powerful feature if it did.
Ok another example, this is pretty much what I'm trying to do.
class Shape{}
class Rectangle extends Shape{
//rectangle data
}
class Circle extends Shape{
//circle data
}
Overloaded functions (members of another class)
boolean checkIntersection(Rectangle r, Circle c){}
boolean checkIntersection(Circle c, Circle c){}
//main program
Vector<Shape> shapes = new Vector<Shape>();
shapes.add(new Rectangle());
shapes.add(new Circle());
shapes.add(new Circle());
checkIntersection(shapes.get(0),shapes.get(1));
checkIntersection(shapes.get(1),shapes.get(2));