blob: 64a96d2f6d1280c442cca025424a89aca7731d02 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
[[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).
|