[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?
|
- From: Andy Clement <andrew.clement@xxxxxxxxx>
- Date: Thu, 1 Oct 2009 15:10:59 -0700
- Delivered-to: aspectj-users@eclipse.org
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=0bERghByvHnRRX/HmKkY4gt+gq/aQFdh/Bp6JFxRvEo=; b=Lb+R7cwqtCLX46Bvd3djM+cr0XVwSzPa2zI/kSgAGATVTEUeP4kdQVFjkjZAKanxXu oAFShik+PO+cM9LlhyirlOrkhLCcrnS4hjB7CjpYqEUgwS6XiiQqbgZ5/cvRqhrB0Ssi wtW3qFW9l4Cjp2cEg9uL+7vEmGNPoinxQlLLo=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=BZHDeDS5alcrIJOgMxPFTCBMr5OCTaxZa7yC/Eop17TWCCHQU7du1EhBmIZzRrGPUN TDTWOk0EvrTwwEqFDjMZYvwOZqAe9DlGHEZeyBWmNMuqZRjrb9mY/YSCf9w/eYh5+p2y dOOcOmgeFhk5ZsLF9cXnnYZk+5dhwLVKUh+VA=
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
>