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

  • SEARCH
  • Home
  • 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 7987937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:17:30+00:00 2026-06-04T12:17:30+00:00

I want to add annotations on my classes properties, and then iterate all my

  • 0

I want to add annotations on my classes properties, and then iterate all my properties with the ability to lookup the annotations also.

So for example, I have a class like:

public class User {

   @Annotation1
   private int id;
   @Annotation2
   private String name;
   private int age;

   // getters and setters
}

Now I want to be able to loop through my properties, and be able to know what annotation (if any) is on the property.

I want to know how to do this using just java, but also curious if using either spring, guava or google guice would make this any easier (if they have any helpers to do this easier).

  • 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-04T12:17:31+00:00Added an answer on June 4, 2026 at 12:17 pm

    Here is an example that utilizes the (barely maintained) bean instrospection framework. It’s an all Java solution that you can extend to fit your needs.

    public class BeanProcessor {
       public static void main(String[] args) {
          try {
             final Class<?> beanClazz = BBean.class;
             BeanInfo info = Introspector.getBeanInfo(beanClazz);
             PropertyDescriptor[] propertyInfo = info.getPropertyDescriptors();
             for (final PropertyDescriptor descriptor : propertyInfo) {
                try {
                   final Field field = beanClazz.getDeclaredField(descriptor
                         .getName());
                   System.out.println(field);
                   for (final Annotation annotation : field
                         .getDeclaredAnnotations()) {
                      System.out.println("Annotation: " + annotation);
                   }
    
                } catch (final NoSuchFieldException nsfe) {
                   // ignore these
                }
             }
          } catch (Exception e) {
             e.printStackTrace();
          }
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have all my annotations(as nsdictionnaries) in an array , and the users add
Suppose that I have two classes, first a class without any properties, fields or
I have a multiplatform application and want to add audio annotations functionality. I am
I have a project which I want to add plugins. I have all the
I have a User class marked as entity which also implements UserDetails. I want
I want add my custom sidebar next right column all page. Please check this
I have a website built with ASP.NET (3.5) and want add some level of
I have a list of string values that I want add to a hashtable
I have problem, when I want add Node to my GUI from other Thread.
I have numbers in javascript from 01(int) to 09(int) and I want add 1(int)

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.