Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] InterType: introducing serialVersionUIDinto@Persistable

On the next beautiful day: Mon, 19 September, 2005, Antti Karanta wrote:

> > > public aspect MyAspect {
> > >   interface PersistenceAware { 
> > >     long serialVersionUID = 17; // this is static final
> > >   }
> > >   declare parents: @Persistable * implements PersistenceAware;
> > > }   
> 
>   The above is not supposed to do that. It declares a public static
> final field in a normal Java interface (only aj thing here is that this
> interface is declared within an aspect) and makes your classes implement
> that interface. A class implementing an interface gets all the constants
> (i.e. static finals) declared in the implemented interface to its
> namespace. 

No. A class will not get the static, final fields -- constants.

Although call to MyClass.XXX where XXX is a constant 
of PersistenceAware interface is valid.

It seems 'ajc' changes calls to MyClass.XXX into the _value_ of its.


> The thing I'm not sure about is whether the serialization
> mechanism is happy w/ a public static final field that is in the class'
> namespace due to implementing an interface that has the field or whether
> it requires that the field must be declared in the class itself, and not
> inherited from a superclass / implemented interface.

Serialization is only happy, when the 'serialVersionUID' is in the
class' source file. Not in the inherited interface, or parent class or
inner interface, or anything. Only in the class itself.

>   That is, after doing the above, this should work:
> public @Persistable class MyClass {
>   // ...
> }
> 
> long foo = MyClass.serialVersionUID;

Like said above, yes it works with a trick/optimization of 'ajc'.


>   But I'm not sure whether that is good enough for the serialization
> mechanism.

Like said above: not, because the declaration of that field doesn't
exist in the resulting *.class file.


Why 'ajc' cannot simply put the declaration in the class implementing
the interface in a case of:
    static final long @Persistable.anyField = anyValue;

I believe it is a very rare case, and nobody thought about that before.
I wouldn't mind if that's a new feature request :)


Tomasz


-- 
  _i______'simplicity_is_the_key'__________tomasz_nazar
  _ii____'i_am_concern_oriented'________________PJKM.pl
  _iii__'patsystem.sf.net'___________________linux_user
  _Heaven_&_Fellows,_PPP______________________prevayler


Back to the top