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.xml 2.5KB

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