Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Re: annotations vs. marker interfaces

aspectj-users-request@xxxxxxxxxxx writes:
Date: Tue, 01 Nov 2005 16:56:58 -0800
From: "Wes Isberg" <wes@xxxxxxxxxxxxxx>
Subject: Re: [aspectj-users] annotations vs. marker interfaces
To: aspectj-users@xxxxxxxxxxx
Message-ID: <web-104616354@xxxxxxxxxxxxxx>
Content-Type: text/plain; charset="ISO-8859-1" Hi -
You're right that annotations don't replace interfaces, but
I'm not sure they're intended to.
I'm not sure who promised that annotations would replace
marker interfaces.  It's of course possible that some uses
of tag interfaces can be replaced - particularly where
you'd like to avoid targeting subtypes of the tagged types
(and the annotation is not inherited (default)).

There were some comments in the list before the advent of Java 5, but I don't recall exactly. Anyway, the comments I seem to recall were not specifically about using annotations to support mixins, and I probably misunderstood.
(I don't think the implementation of the Observer pattern
just uses marker interfaces.  To me, when you declare a
member on an interface and declare that a class implements
the interface, you're using the interface as a mixin (not
just a marker aka tag).)

We're definitely talking about mixins here. Perhaps tag interface is a better name than marker interface (they are often used to represent abstract roles).
wrt ITD's, Since 1.1, inter-type declarations must resolve
to a specific type at compile time.  You used to be able to
use a typepattern: void (Foo || Bar).go(){}
Now it has to be a type (it may be an interface).  One
reason is so "this" in the body has a given declared
compile-time type.   E.g., if the declared type is an
interface, then you will not be able to refer to a method
on a target type (not in the interface) without casting.

I see... In such case the type of "this" would probably have to be Object, which is definitly not type safe.

e.g.,
  // given
  interface IFoo{}
  class C {
    void bar() {}
  }
// and in an aspect..
  declare parents : C implements IFoo ;
public void IFoo.foo() { bar(); // illegal - no bar() in IFoo
      ((C) this).bar(); // works for C, not for others
}
Does that make sense?  The statement about annotations and
ITD's just extend the 1.1 rule to the case of
annotation-based type patterns.

Yes, it does make sense. It's just that I never gave a deep thought about the implications and simply waited for what would come up... Thanks, Wes. Miguel Monteiro

Wes
On Tue, 01 Nov 2005 19:51:06 +0000
 mmonteiro@xxxxxxxxxxxx wrote:
Hi everybody, I've been experimenting with the latest features of
AspectJ 5. In particular, I wanted to assess whether
annotations can completely replace marker interfaces.
That was an early promise of annotations before the
advent of AspectJ 5, if I recall correctly.
If annotations can really replace marker interfaces, it
should be possible to rewrite the widely known
implementation of the Observer pattern by
Hannemann/Kiczales using annotations such @Subject and
@Observer, in place of the Subject and Observer marker
interfaces... However, the documentation accompanying AJDT says that
"An annotation type may not be the target of an
inter-type declaration"
Well, I see two ways to interpret this:
a) we cannot use ITDs add state and behaviour to
annotation types.
b) we cannot use ITDs to add state and behaviour to types
_referred through annotation types_. a) makes sense, but I'm not sure the doc means b) as
well.
If b) is true as well, annotations cannot be used in
place of marker interfaces. Is this correct, or am I
missing something? Thanks, Miguel Pessoa Monteiro, Ph.D.
URL: http://gec.di.uminho.pt/mpm/
Escola Superior de Tecnologia de Castelo Branco
ESTCB URL: http://www.est.ipcb.pt/portal/
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users




Back to the top