123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- [[enumeratedtypes]]
- = Enumerated Types
-
- [[enums-in-java5]]
- == Enumerated Types in Java 5
-
- Java 5 (and hence AspectJ 5) provides explicit support for enumerated
- types. In the simplest case, you can declare an enumerated type as
- follows:
-
- [source, java]
- ....
- public enum ProgrammingLanguages {
- COBOL, C, JAVA, ASPECTJ
- }
- ....
-
- Enumerated types are just classes, and they can contain method and field
- declarations, and may implement interfaces. Enums may only have private
- constructors, and may not be extended.
-
- Enumerated types in Java 5 all implicitly extend the type
- `java.lang.Enum`. It is illegal to explicitly declare a subtype of this
- class.
-
- [[enums-in-aspectj5]]
- == Enumerated Types in AspectJ 5
-
- AspectJ 5 supports the declaration of enumerated types just as Java 5
- does. Because of the special restrictions Java 5 places around
- enumerated types, AspectJ makes the following additional restrictions:
-
- * 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.
-
- 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.
-
- If an enum is named explicitly as the target of a declare parents
- statement, a compilation error will result. If an enumerated type is
- matched by a non-explicit type pattern used in a declare parents
- statement it will be ignored (and an XLint warning issued).
|