You are viewing a plain text version of this content. The canonical link for it is here.
Posted to bcel-user@jakarta.apache.org by Dick Eimers <dw...@cs.uu.nl> on 2005/06/04 09:13:01 UTC

RE: Telling the difference between a self reference and a base class reference

> Is it possible to distinguish that a method being referenced for a class is
> actually implemented in a base class?  See example below.

You cannot know this statically. It could even be the case that some
subclass of Triangle (e.g. EquilateralTriangle) defines its own
redefinition. If you are naive you can iterate over the method defined
in a class, and up the hierarchy until you find an implementation, but
this will only work for static methods..

The fact that you example uses a constructor makes it worse. Consider
this 'horrible' extension to your problem;

public class EquilateralTriangle extends Triangle {
  EquilateralTriangle() { setTypeName("EquilateralTriangle"); }
  void draw() { System.out.println("EquilateralTriangle"); }
  
  public void setTypeName (String typename) {
    super.setTypeName(typename);
  }
  
  public static void main(String args[])
  {
    EquilateralTriangle x = new EquilateralTriangle();
  }
}



---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org