Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] initialising instance variables

From memory only, I believe that you had:

b = new Foo();

where b was some inherited instance variable. That has to be in a
constructor or initialier because it's not part of a member declaration.

This:

>   private PropertyChangeSupport Point.support = new
> PropertyChangeSupport(this);

is part of one.

That is (I *think*) the answer to the first implicit problem.

As to your follow-on question, I need a clarification:

> If I make the instance variables static and add a
> static constructor to LoggingAspect, it compiles (and
> works) fine.

What do you mean by "static constructor"?

Cheers,
Nick
--- Aaron Blishen <aaron_blishen@xxxxxxxxx> wrote:
> Hi All,
> 
> I have tried to intialise the intance variables in a
> constructor (I assumed that one was not needed as some
> of the examples in the programming guide do not have
> one) i.e:
> 
> aspect BoundPoint {
>   private PropertyChangeSupport Point.support = new
> PropertyChangeSupport(this);
> 
>   ....
>   
>  }
> Is this becuase the aspect is adding an instance
> variable to the class Point, and adds initialisation
> of support into the Point constructor?
> 
> Here is my problem when I add a constructor:
> 
> public abstract aspect LoggingAspect
> {
>   // call depth per logger
>   protected int callDepth;
>   
>   // (commons) Log4j logger
>   protected Log log;
>   
>   // class unspecified
>   public abstract pointcut cutClass(Object o);
>   
>   // pointcuts and advice for intercepting constructor
> and 
>   // method calls based on unspecified class
> }
> 
> public aspect myClassLogger extends LoggingAspect
> {
>   // initialise logger and calldepth
>   public myClassLogger()
>   {
>     callDepth = 2;
>     log       = LogFactory.getLogger
> (myClassLogger.class);
>   }
>   
>   public pointcut cutClass(Object o) : this(o)
>     && within(com.foo.myClass);
>     
>   // custom logging methods for myClass
> }
> 
> The compiler complains:
> 
> inherited abstract pointcut
> LoggingAspect.cutClass(java.lang.Object) is not made
> concrete in com.foo.myClassLogger
> 
> If I make the instance variables static and add a
> static constructor to LoggingAspect, it compiles (and
> works) fine.
> 
> Cheers,
> 
> Aaron.
> 
> __________________________________
> Do you Yahoo!?
> Yahoo! SiteBuilder - Free, easy-to-use web site design software
> http://sitebuilder.yahoo.com
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> http://dev.eclipse.org/mailman/listinfo/aspectj-users



Back to the top