Details
-
Enhancement
-
Resolution: Fixed
-
P4
-
5.0
-
Verified
Description
A DESCRIPTION OF THE REQUEST :
The current Java annotation system is too weak to use for many purposes.
There are two main problems: inability to annotate certain constructs, and
loss of other annotations by the compilation process.
1. Annotations can only be applied to type declarations, not to other uses
of types.
* Annotations cannot be applied to a cast.
* Annotations cannot be applied to the receiver (this) of a method.
(This could be worked around with an annotation that is syntactically
applied to the method return type but semantically applies to the
receiver type.)
* Annotations cannot be inserted at arbitrary locations within array and
parameterized types. Consider annotating the various levels of an
array with different annotations; one would like to say, for example
(@annotation Date[])[][] myarray;
* Annotations are not permitted on type parameters. Consider placing
annotations on various parts of the following type:
Map<List<Date>, Set<Number>>
2. Annotations on local variables are not recorded within the classfile by
the javac compiler. Therefore, if we wish to use annotations and perform
type checking on classfiles, we would be required to extend the annotation
system. This would require changing the compiler, possibly by recording
local variables' annotations within the local variable symbol table. A
compiler change eliminates one of the benefits of using annotations: not
requiring people to use a new compiler to check reference immutability
constraints. (But the Javari code would remain backward-compatible with
other Java compilers.)
JUSTIFICATION :
If these problems were resolved, then the annotation system would become
much more expressive and more useful for a variety of purposes. As just
one example, it would become possible to experiment with new type systems
without changing the syntax of the Java language in an incompatible way.
Other applications would benefit as well.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Annotations should be permitted on any type, and should be preserved
by the compiler.
ACTUAL -
Annotations are prohibited on certain uses of types.
Annotations on local variables are dropped by the compiler.
The current Java annotation system is too weak to use for many purposes.
There are two main problems: inability to annotate certain constructs, and
loss of other annotations by the compilation process.
1. Annotations can only be applied to type declarations, not to other uses
of types.
* Annotations cannot be applied to a cast.
* Annotations cannot be applied to the receiver (this) of a method.
(This could be worked around with an annotation that is syntactically
applied to the method return type but semantically applies to the
receiver type.)
* Annotations cannot be inserted at arbitrary locations within array and
parameterized types. Consider annotating the various levels of an
array with different annotations; one would like to say, for example
(@annotation Date[])[][] myarray;
* Annotations are not permitted on type parameters. Consider placing
annotations on various parts of the following type:
Map<List<Date>, Set<Number>>
2. Annotations on local variables are not recorded within the classfile by
the javac compiler. Therefore, if we wish to use annotations and perform
type checking on classfiles, we would be required to extend the annotation
system. This would require changing the compiler, possibly by recording
local variables' annotations within the local variable symbol table. A
compiler change eliminates one of the benefits of using annotations: not
requiring people to use a new compiler to check reference immutability
constraints. (But the Javari code would remain backward-compatible with
other Java compilers.)
JUSTIFICATION :
If these problems were resolved, then the annotation system would become
much more expressive and more useful for a variety of purposes. As just
one example, it would become possible to experiment with new type systems
without changing the syntax of the Java language in an incompatible way.
Other applications would benefit as well.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Annotations should be permitted on any type, and should be preserved
by the compiler.
ACTUAL -
Annotations are prohibited on certain uses of types.
Annotations on local variables are dropped by the compiler.
Attachments
Issue Links
- duplicates
-
JDK-6970620 Allow annotation on an assignment
-
- Closed
-
-
JDK-6406858 (ann) Annotations for statements
-
- Closed
-
- relates to
-
JDK-6508965 Cannot annotate static or instance initializers
-
- Closed
-