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 8831559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:20:14+00:00 2026-06-14T08:20:14+00:00

This is my code for getting field values and annotation values, I placed the

  • 0

This is my code for getting field values and annotation values, I placed the values into a map, however problem is there is a $this that is in the map.

Map doc = null;
        String kind = null;
        Class classObj = obj.getClass();
        Annotation[] annotations = classObj.getAnnotations();
        for (Annotation annotation : annotations) {
                Entity entityAnnotation = (Entity)annotation; 
                kind = entityAnnotation.name();
                if (entityAnnotation != null){
                        if (doc == null){
                            doc = new LinkedHashMap();
                        }
                        Field[] fields = classObj.getDeclaredFields();
                        for (Field field : fields){
                                annotations = field.getDeclaredAnnotations();
                                String value = null;
                                String fieldName = field.getName();
                                try {
                                        boolean access = field.isAccessible();
                                        field.setAccessible(true);
                                        Object fieldValue = field.get(obj); 
                                        doc.put(fieldName, fieldValue);
                                        field.setAccessible(access);
                                } catch (Exception e) {
                                        e.printStackTrace();
                                }                               
                                // Process fields with annotation
                                for(Annotation fieldAnnotation : annotations){
                                    if (annotation instanceof Id){
                                        Id idAnnotation = (Id) fieldAnnotation;
                                        log.info("Field name="+fieldName+" "+ value + " Annotation value: " + idAnnotation.value()); 
                                        doc.put("_id", value);
                                    }                                   
                                }
                        }                               
                }
        }

Test output:

Key=id value=id1
Key=name value=Eli
Key=age value=25
Key=this$0 value=org.goo.AnnotationTest@7f5227
  • 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-14T08:20:15+00:00Added an answer on June 14, 2026 at 8:20 am

    The field this$0 is the reference to the outer class.

    If you want to avoid this, make the class static. IMHO you should make nested class static where possible, partly for performance, but mostly for clarity. If this is not an option, you can ignore that field explicitly.

    BTW: If you create a field called this$0 it will use the field this$$0 or this$$$0 or this$$$$0 etc instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a problem with getting this code to print out to file due
I am having a problem getting this code to work. Basically I Go from
this is the code PreparedStatement res1 = null; String insertUser = INSERT INTO users
This code compiled properly on Visual Studio 2010 on Windows, but I'm getting this
I am getting a StackOverflow Error in this code: EDIT [XmlAttribute(ID)] public string ID
I am getting segmentation fault in this code but i cant figure out why.
I have this code and I keep getting undefined if I test the selectedIndex.
I am Getting a run time Exception while using this code Runtime rt =
I'm not really getting how this code does what it does: char shellcode[] =
I am getting a file not found exception for this code: (System.IO.FileNotFoundException : Die

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.