Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Anonymous classes unaware of introductions into abstract classes



Marius,

You are missing something. Although you have an inter-type declared method
for "a2()" on AbstractClassA the statement "AbstractClassA is a InterfaceA"
is not true hence the compiler error:

      Type mismatch: cannot convert from <anonymous subclass of
AbstractClassA> to InterfaceA

You also need a declare parents statement:

public aspect IntroAspectA {

      declare parents : AbstractClassA implements InterfaceA;

      public void AbstractClassA.a2() {
            System.out.println("AbstractClassA.a2() from IntroAspectA");
      }
}

Matthew Webster
AOSD Project
Java Technology Centre, MP146
IBM Hursley Park, Winchester,  SO21 2JN, England
Telephone: +44 196 2816139 (external) 246139 (internal)
Email: Matthew Webster/UK/IBM @ IBMGB, matthew_webster@xxxxxxxxxx
http://w3.hursley.ibm.com/~websterm/


"Marius M." <marin_marius@xxxxxxxxx>@eclipse.org on 07/10/2004 13:21:06

Please respond to aspectj-users@xxxxxxxxxxx

Sent by:    aspectj-users-admin@xxxxxxxxxxx


To:    aspectj-users@xxxxxxxxxxx
cc:
Subject:    [aspectj-users] Anonymous classes unaware of introductions into
       abstract classes


Hello,


 I couldn't find this problem reported as a bug, but I think it is a
 compiler bug. It seems that anonymous classes are not able to "see" the
 methods introduced by aspects into abstract classes.


 Apparently, the previous version of the ajc compiler had this problem for
 concrete classes as well, but it was fixed in aspectj 1.2. Yet, it doesn't
 work for anonymous classes:





 interface InterfaceA {


  public void a1();

  public void a2();

 }


 abstract class AbstractClassA implements InterfaceA {


  public void a1() {
   System.out.println("AbstractClassA.a()");
  }

 }



 public class ConcreteClassA extends AbstractClassA {


  public void someMethod() {
   InterfaceA a = new AbstractClassA() {
   };
  }

 }


 aspect IntroAspectA {


  public void AbstractClassA.a2() {
   System.out.println("AbstractClassA.a2() from IntroAspectA");
  }
 }





 The compiler will complain about the anonymous class as not having
 implemented the method a2(). However, it will work if the AbstractClassA
 is not abstract (or if the class is not anonymous :-)).





 Thanks,


 Marius M.





Do you Yahoo!?
Take Yahoo! Mail with you! Get it on your mobile phone.




Back to the top