A DESCRIPTION OF THE REQUEST :
It is currently not possible in the Java Language to use references to fields holding constant Class Literal Arrays in the place of Annotation Values. This means that while it is possible to use the following annotation:
@SomeAnnotation({ int.class, float.class }
It is not possible to do the following:
public static final Class[] INTFLOAT = { int.class, float.class }
@SomeAnnotation(INTFLOAT)
This seems counter-intuitive, since it is possible to use references to other constant fields as annotation values, but not references to fields holding constant Class Literal arrays.
JUSTIFICATION :
The inability to use references to constant Class Literal Arrays requires the duplication and, connected to this, the decreased readability and maintainability of code that involves Arrays using Class arrays.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
References to fields holding arrays of Class Literals should be usable in the place of annotation values that require Class Arrays.
ACTUAL -
Using a Reference in the place of a Class Array annotation parameter causes the compiler error 'The value for annotation attribute AnnotationType.Attribute must be a class literal', where AnnotationType.Attribute is an annotation method of the type `Class[]`.
---------- BEGIN SOURCE ----------
@specialized(specialized.COMMONS)
public @interface specialized
{
Class[] COMMONS = { int.class, long.class, float.class, double.class };
public Class[] value() default COMMONS;
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Replacing the reference to a constant array field with it's value.
It is currently not possible in the Java Language to use references to fields holding constant Class Literal Arrays in the place of Annotation Values. This means that while it is possible to use the following annotation:
@SomeAnnotation({ int.class, float.class }
It is not possible to do the following:
public static final Class[] INTFLOAT = { int.class, float.class }
@SomeAnnotation(INTFLOAT)
This seems counter-intuitive, since it is possible to use references to other constant fields as annotation values, but not references to fields holding constant Class Literal arrays.
JUSTIFICATION :
The inability to use references to constant Class Literal Arrays requires the duplication and, connected to this, the decreased readability and maintainability of code that involves Arrays using Class arrays.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
References to fields holding arrays of Class Literals should be usable in the place of annotation values that require Class Arrays.
ACTUAL -
Using a Reference in the place of a Class Array annotation parameter causes the compiler error 'The value for annotation attribute AnnotationType.Attribute must be a class literal', where AnnotationType.Attribute is an annotation method of the type `Class[]`.
---------- BEGIN SOURCE ----------
@specialized(specialized.COMMONS)
public @interface specialized
{
Class[] COMMONS = { int.class, long.class, float.class, double.class };
public Class[] value() default COMMONS;
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Replacing the reference to a constant array field with it's value.