[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[aspectj-users] Intertype declaration with methods returning instances of the class itself - correction
|
Em Sexta, 17 de Fevereiro de 2006 09:54, o Paulo Alexandre Corigo Zenida
escreveu:
> Hi all,
>
> I wonder if, in Intertype declaration, is it possible for me to add
> a method to any class with a common characteristic (annotated with
> something, for example, that returns an instance of the class itself? To
> better understand what I want, let me show an example:
>
> @MyAnnotation
> public class A {
>
> }
>
> @MyAnnotation
> public class B {
>
> }
>
> public aspect MyAspect {
>
> // this does not compile
> public void (@MyAnnotation *).foo() {
>
> }
>
> // So, I have tried this:
> declare parents : (@MyAnnotation *) implements MyInterface;
>
> interface MyInterface {
>
> }
>
> // this works ok
> public void MyInterface.foo() {
> System.out.println("In foo");
> }
>
> // But this does not compile! I would like to create a
> // method returning an instance of the class itself.
> // Any ideas about how to do this?
> public (@Singleton *) getInstance() {
> return new (@Singleton *)();
> }
What I mean was
public (@MyInterface *) getInstance() {
return new (@MyInterface *)();
}
}
>
> Is the previous possible?
>
> Thanks in advance. Cheers,
>
> Paulo Zenida