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

Dick Eimers <[email protected]>
Newsgroups gmane.comp.jakarta.bcel.user
Organization cs.uu.nl
Message-ID <[email protected]>
> 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();
  }
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.