[aspectc-user] Base class substitution

Francisco Afonso afonsofc at hotmail.com
Mon Apr 2 10:46:45 CEST 2007


I have tried to do it in AspectJ, and it works.
This is my example code.

public class Base {
  void operation(){

public class Derived extends Base {

public class Base2 extends Base{
  void operation(){

public class Test {

  public static void main(String[] args) {

       Base bb1 = new Base();

       Base bb2 = new Derived();

public aspect Intro {
   declare parents: Derived  extends Base2;

Program output:


As in Java there is no multiple inheritance, a "declare parent" for a 
derived class will replace the old base class.
But this is allowed only if the new base class derives from the old one, 
otherwise the following message is displayed:
"can only insert a class into hierarchy, but ____ is not a subtype of ____".

I think that it would be nice if in AspectC++ we could define if an 
introduction of a base class would be implemented by addiction or 

Francisco Afonso

Live Search Maps – find all the local information you need, right when you 
need it. http://maps.live.com/?icid=hmtag2&FORM=MGAC01

More information about the aspectc-user mailing list