You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

enumeratedtypes.adoc 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. [[enumeratedtypes]]
  2. = Enumerated Types
  3. [[enums-in-java5]]
  4. == Enumerated Types in Java 5
  5. Java 5 (and hence AspectJ 5) provides explicit support for enumerated
  6. types. In the simplest case, you can declare an enumerated type as
  7. follows:
  8. [source, java]
  9. ....
  10. public enum ProgrammingLanguages {
  11. COBOL, C, JAVA, ASPECTJ
  12. }
  13. ....
  14. Enumerated types are just classes, and they can contain method and field
  15. declarations, and may implement interfaces. Enums may only have private
  16. constructors, and may not be extended.
  17. Enumerated types in Java 5 all implicitly extend the type
  18. `java.lang.Enum`. It is illegal to explicitly declare a subtype of this
  19. class.
  20. [[enums-in-aspectj5]]
  21. == Enumerated Types in AspectJ 5
  22. AspectJ 5 supports the declaration of enumerated types just as Java 5
  23. does. Because of the special restrictions Java 5 places around
  24. enumerated types, AspectJ makes the following additional restrictions:
  25. * You cannot use declare parents to change the super type of an enum.
  26. * You cannot use declare parents to declare `java.lang.Enum` as the parent
  27. of any type.
  28. * You cannot make inter-type constructor declarations on an enum.
  29. * You cannot extend the set of values in an enum via any ITD-like
  30. construct.
  31. * You cannot make inter-type method or field declarations on an enum.
  32. * You cannot use declare parents to make an enum type implement an
  33. interface.
  34. In theory, the last of these two items _could_ be supported. However,
  35. AspectJ 5 follows the simple rule that _an enum type cannot be the
  36. target of an inter-type declaration or declare parents statement_. This
  37. position may be relaxed in a future version of AspectJ.
  38. If an enum is named explicitly as the target of a declare parents
  39. statement, a compilation error will result. If an enumerated type is
  40. matched by a non-explicit type pattern used in a declare parents
  41. statement it will be ignored (and an XLint warning issued).