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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:38:21+00:00 2026-06-14T19:38:21+00:00

I ask this question because I’m curious. I don’t want to actually traverse the

  • 0

I ask this question because I’m curious. I don’t want to actually traverse the derived classes of a class. I know that the method I present here is sloppy this is just a test.

So suppose I have a class (abstract or not):

    public class SomeClass {
        // snip....
    }

I can easily write a method to walk up the class hierarchy and find a Field for example:

    private Field extractField(Class<?> type, String fieldName) {
        Field ret = null;
        try {
            ret = type.getDeclaredField(fieldName);
        } catch (NoSuchFieldException e) {
            Class<?> superclass = type.getSuperclass();
            if (superclass == null) {
                throw new IllegalArgumentException("Missing field detected.", e);
            } else {
                ret = extractField(superclass, fieldName);
            }
        }
        return ret;
    }

Now what can I do If I wish to search for a Field in the derived classes of type? I did not find anything useful in the java reflection packages.

  • 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-14T19:38:22+00:00Added an answer on June 14, 2026 at 7:38 pm

    There is no simple way to traverse derived classes as you don’t know which classes are derived from a base class. You can use the Reflections library to find derived classes. This works by examining the byte code of the classes in your class path, optionally limited to package(s) or pre-indexed.

    Now what can I do If I wish to search for a Field in the derived classes of type?

    Once you have found the derived classes you can examine these in the same way.

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

Sidebar

Related Questions

Not really sure how to ask this question because I really don't know what
Before I ask this question I would to apologise because of the fact that
I ask this question because i learned that in programming and designing, you must
I ask this question because it appears that viewDidLoad gets called before the main
I'm quite ashemed to ask this question here because I'm sure that I'm missing
First...if no one can answer this question it's ok... because I don't know how
I know it is a little bit lazy to ask this question here because
I ask this question because I'm not able to test it at the moment.
I have to ask this question because I'm stuck, and I think its because
I'm not sure StackOverflow is the right place to ask this question, because this

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.