Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Assignment to final field on inter-type declaration in initializer

Dear Wes, and all,

> (Sorry for my earlier brevity and for saying the obvious...)

Never mind.

> One way to do that in Java is with static methods:
> 
> aspect A {
>       private static List initList() {
>           List list = new ArrayList();
>   	 list.add(new Integer(1));
>   	 list.add(new Integer(5));
> 	 return list;
>       }
>       final static List aClass.aField = initList();
> }

Ah, this is reasonable!  I rewrite my program right away.

> In any case, I believe that the compiler does not do
> the flow analysis required to handle assignments to
> final fields in advice on static initialization
> join points.

To consider to implement compiler, an assignment to final field does
not allowed except constructors or static initializers, so the
assignment cannot be placed in the aspect.  Then, the compiler cannot
map the aspect class file to its source file.

> Hope this helps...
> Wes

Thank you!

Susumu YAMAZAKI <yamazaki@xxxxxxxxxxxxxxx>

> Susumu YAMAZAKI wrote:
> 
> > Dear Wes, and all,
> > 
> > From: Wes Isberg <wes@xxxxxxxxxxxxxx>
> > Subject: Re: [aspectj-users] Assignment to final field on inter-type declaration in initializer
> > Date: Tue, 05 Aug 2003 22:55:38 -0700
> > 
> > 
> >>As in Java, set finals in the initializer:



> >>
> >>    static final int aClass.aField = 0;
> > 
> > 
> > I know.  But I would like to write the case that the assigned value is
> > too complex to write a single statement:
> > 
> > class aClass{}
> > 
> > aspect AnAspect {
> >     final static List aClass.aField;
> >     after() : staticitinialization(aClass) {
> >         List list = new ArrayList();
> > 	list.add(new Integer(1));
> > 	list.add(new Integer(5));
> >         aClass.aField = Collections.unmodifiableList(list);
> >     }
> > }
> > 
> > 
> > 
> >>Susumu YAMAZAKI wrote:
> >>
> >>>Dear all,
> >>>
> >>>I would like to assign a value to a final (static) field on inter-type
> >>>declaration in static initializer as follows, but AspectJ does not
> >>>allow this:
> >>>
> >>>aspect AnAspect {
> >>>    static class aClass {}
> >>>    final static int aClass.aField;
> >>>    after() : staticinitialization(aClass) {
> >>>        aClass.aField = 0;
> >>>    }
> >>>}
> >>>
> >>>any ideas?
> >>>
> >>>Thanks,
> >>>
> >>>Susumu YAMAZAKI <yamazaki@xxxxxxxxxxxxxxx>
> >>>_______________________________________________
> >>>aspectj-users mailing list
> >>>aspectj-users@xxxxxxxxxxx
> >>>http://dev.eclipse.org/mailman/listinfo/aspectj-users
> >>>
> >>
> >>_______________________________________________
> >>aspectj-users mailing list
> >>aspectj-users@xxxxxxxxxxx
> >>http://dev.eclipse.org/mailman/listinfo/aspectj-users
> > 
> > 
> > Susumu YAMAZAKI <yamazaki@xxxxxxxxxxxxxxx>
> > _______________________________________________
> > aspectj-users mailing list
> > aspectj-users@xxxxxxxxxxx
> > http://dev.eclipse.org/mailman/listinfo/aspectj-users
> > 
> 
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> http://dev.eclipse.org/mailman/listinfo/aspectj-users


Back to the top