Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-dev] proposed change to inter-type field declarations made on interfaces.

We are thinking about making a change to how we handle inter-type
field declarations made on interfaces - it is covered in bug 73507 (
https://bugs.eclipse.org/bugs/show_bug.cgi?id=73507 ).

Currently when you make a public ITD of a field onto an interface,
every implementor of the interface gets that field.  They get it with
a 'non-visible' mangled name - this allows us to cope with clashes
where the implementor of the interface has already defined the field. 
Here is a simple example:

interface I {}
class C implements I {
  public int m;
}
aspect X {
  public int I.m;
}

that is a clashing case where the mangling of the field name makes things OK.

However, it is rather inconsistent with ITD methods on interfaces.  In
the case of methods, the ITD you specify is considered a default
implementation of the method - an implementor of the target interface
that provides no implementation of their own will get the default
implementation, and if they did provide an implementation already,
they are unaffected by the ITD.

We are proposing to make ITD fields behave the same as methods. 
Effectively what you specify in the inter-type declaration would be
the field default.  If an implementor of the interface already
provides the field, they are untouched.  If an implementor of the
interface doesn't define the field, they get the definition from the
ITD in the aspect - the name is not mangled.

So, after this program has compiled:

interface I {}

class C implements I {
}

class C2 implements I {
  public int m = 4;
}

aspect X {
  public int I.m = 1;
}

Class C has a public field called m with initial value '1' (it picked
up the ITD declaration).
Class C2 has a public field called m with initial value '4' (it kept
its own declaration).

(yes, this means you people who want to stick serial version uid
fields into some bunch of types can use this change)

Any comments?  Would this change destroy your system design?

Andy.


Back to the top