Can java annotation have complex return type like HashMap
annotations, collections, java
Solution
No, annotation elements can only be primitive types, Strings, `enum` types, `Class`, other annotations, or arrays of any of these. The typical way to represent these kinds of structures would be to declare another annotation type
public @interface TableMapping {
public String dbName();
public String tableName();
}
then say
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface column {
public TableMapping[] table();
}
And use the annotation as
@column(table={
@TableMapping(dbName="dbName", tableName="tableName"),
@TableMapping(dbName="db2", tableName="table2")
})
public String userId = "userid";
Problem
Can annotation have complex return type, such as HashMap. I am looking for something like: ``` @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface column { public HashMap<String, String> table(); } ``` so I can have a constant annotated like(pseudo code): ``` @column({table=(dbName, tableName), table=(dbName, tableName2)}) public static final String USER_ID = "userid"; ``` If Annotation doesn't allow you to have complex return type, then any good practice for this kind of case?