Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [aspectj-users] Intertype Declaration for only one target ?!? !?!?

Stefan Hanenberg wrote:
> I just read the readme of Version 1.1beta4. There is read "One target
> for intertype declarations"......and am totally confused.......

I hope that you're just confused about what those words mean.

> I agree that very often the "container introduction" idiom is used,
> i.e.
> introducing stuff to an interface and then introduce this interface to
> a
> class. So often it looks like as if there is only target of a member
> introduction. However, when the container is introduced to a number of
> classes I really enjoyed writing:
>   declare parent: (A | B | C | D) implements Container

This still works perfectly well in 1.1, and is absolutely the recommended style.  The only thing that you can't write directly is,

    String (A | B | C | D).value = "string" + this.someMethod();

The issues with the above is that it needs to be treated as four separate introductions for the purposes of type-checking (do A, B, C and D all have a someMethod()) and even for code-generation (the generated code will be very different depending on the return type of someMethod()).

The new style lets you have many effective targets for an introduction; the only issue is that the body of the introduction must see a single type, i.e.

    interface Container { String someMethod(); }
    declare parents: (A | B | C | D) implements Container;
    String Container.value = "string" + this.someMethod();

Here the introduction can be separately type-checked and code generated for it because 'this' is an instance of Container.  However, that doesn't stop your declare parents from working as before.

Is this more clear (and less scary)? - Jim

Back to the top