title: Overloading methods using derived class objects referenced by base class - java
body: <pre><code>class base{}
  
  class childA extends base{}
  
  class childB extends base{}
  </code></pre>
  
  <p>I have two functions (overloaded)
  like this:</p>
  
  <pre><code>function(childA,childA){}
  
  function(childA,childB){}
  </code></pre>
  
  <p>//main program</p>
  
  <pre><code>base a = new childA();
  base b = new childB();
  
  function(a,b);   
  function(a,a);  //problem
  </code></pre>
  
  <p>The function calls won't compile obviously.</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>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 :)).</p>
  
  <p>Edit :</p>
  
  <p>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.</p>
  
  <p>Ok another example, this is pretty much what I'm trying to do.</p>
  
  <pre><code>class Shape{}
  
  class Rectangle extends Shape{
  //rectangle data
  }
  
  class Circle extends Shape{
  //circle data
  }
  </code></pre>
  
  <p>Overloaded functions (members of another class)</p>
  
  <pre><code>boolean checkIntersection(Rectangle r, Circle c){}
  boolean checkIntersection(Circle c, Circle c){}
  </code></pre>
  
  <p>//main program</p>
  
  <pre><code>Vector&lt;Shape&gt; shapes = new Vector&lt;Shape&gt;();
  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));
  </code></pre>