Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8887729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:52:55+00:00 2026-06-14T21:52:55+00:00

Can annotation have complex return type, such as HashMap. I am looking for something

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T21:52:56+00:00Added an answer on June 14, 2026 at 9:52 pm

    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";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an annotation @MyAnnotation and I can annotate any type (class) with it.
If I have a parametrized annotation which is used on a field, can the
I have a single annotation on a map view. I can select it programmaticly,
Let's say I have an annotation JSR 303 class like this: class A {
Is there an annotation/attribute which can be set on a controller method, to have
In my application i have used mapview. On particular place i can put annotation.
I would like to know if @JsonTypeInfo annotation can be used for interfaces. I
I have a complex object I'm getting back as a return value from the
Can I have an annotation for a method that when its parameters are null,
I would like to build an extended DisplayAttribute annotation that can detect if the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.