Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] How do you introduce a method on a Java5 enum?

Hi Matthew,

Unfortunately that is not allowed.  Per the developers notebook (
http://www.eclipse.org/aspectj/doc/released/adk15notebook/enums-in-aspectj5.html
):

    * You cannot use declare parents to change the super type of an enum.
    * You cannot use declare parents to declare java.lang.Enum as the
parent of any type.
    * You cannot make inter-type constructor declarations on an enum.
    * You cannot extend the set of values in an enum via any ITD-like construct.
    * You cannot make inter-type method or field declarations on an enum.
    * You cannot use declare parents to make an enum type implement an
interface.

But as it also says on that page:
"In theory, the last of these two items could  be supported. However,
AspectJ 5 follows the simple rule that  an enum type cannot be the
target of an inter-type declaration or declare parents statement. This
position may be relaxed in a future version of AspectJ."

We just haven't had many users requesting that feature, so no work has
been done on it.

cheers,
Andy.


2009/10/1 Matthew Adams <matthew@xxxxxxxxxxxxxxx>:
> I want to add a method to all enums with the signature "String getName()".
>
> Any ideas?
>
> This doesn't appear to work:
>
> public aspect GetNameEnumIntroduction {
>
>        interface Introduced { String name(); }
>
>        declare parents : (Enum+) implements Introduced;
>
>        public String Introduced.getName() {
>                return this.name();
>        }
> }
>
> It also doesn't work if I change the type expression of declare
> parents to (Enum<? extends Enum>+).
>
> Thanks,
> Matthew
>
> --
> mailto:matthew@xxxxxxxxxxxxxxx
> skype:matthewadams12
> yahoo:matthewadams
> aol:matthewadams12
> google-talk:matthewadams12@xxxxxxxxx
> msn:matthew@xxxxxxxxxxxxxxx
> http://matthewadams.me
> http://www.linkedin.com/in/matthewadams
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>


Back to the top