[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] around advice for constructor pointcut

Hi -

Ron's right, but I suspect you need to use call(..).

The return type of constructor-execution is void, but the
return type of constructor-call is whatever type is 
being constructed, so use

  Foo around() : call(Foo.new()) { ... }

If caching more than one type, use Object:

  Object around() : call(Foo+.new()) { ... }

The compiler will be ok and the AspectJ runtime will do the
right thing when the type is correct, but you can get
runtime ClassCastException if you return the wrong type
for that join point.

See also
  http://www.eclipse.org/aspectj/doc/released/faq.html#q:initializationjoinpoints
http://www.eclipse.org/aspectj/doc/released/faq.html#q:adviseconstructors

Wes

On Wed, 18 Jan 2006 00:43:20 -0500
 Nilesh Jain <nilesh82@xxxxxxxxx> wrote:
> Hi ,
> I need to prevent creation of an object using aspect. For
> this I have  declared a pointcut with constructor
> signature. But I cannot use that  pointcut with around
> advice because around advice need us to specify  a return
> type. Please help me out this. Is there another way to
>  prevent construction of an object?
> Thanks.
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users