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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:06:45+00:00 2026-05-13T06:06:45+00:00

Is there a way to get a list of methods that would be accessible

  • 0

Is there a way to get a list of methods that would be accessible (not necessarily public) by a given class? The code in question will be in a completely different class.

Example:

public class A {
  public void methodA1();
  protected void methodA2();
  void methodA3();
  private void methodA4();
}

public class B extends A {
  public void methodB1();
  protected void methodB2();
  private void methodB3();
}

For class B I’d like to get:

  • all of its own methods
  • methodA1 and methodA2 from class A
  • methodA3 if and only if class B is in the same package as A

methodA4 should never be included in results because it’s inaccessible to class B. To clarify once again, code that needs to find and return the above methods will be in a completely different class / package.

Now, Class.getMethods() only returns public methods and thus won’t do what I want; Class.getDeclaredMethods() only returns methods for current class. While I can certainly use the latter and walk the class hierarchy up checking the visibility rules manually, I’d rather not if there’s a better solution. Am I missing something glaringly obvious here?

  • 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-05-13T06:06:46+00:00Added an answer on May 13, 2026 at 6:06 am

    Use Class.getDeclaredMethods() to get a list of all methods (private or otherwise) from the class or interface.

    Class c = ob.getClass();
    for (Method method : c.getDeclaredMethods()) {
      if (method.getAnnotation(PostConstruct.class) != null) {
        System.out.println(method.getName());
      }
    }
    

    Note: this excludes inherited methods. Use Class.getMethods() for that. It will return all public methods (inherited or not).

    To do a comprehensive list of everything a class can access (including inherited methods), you will need to traverse the tree of classes it extends. So:

    Class c = ob.getClass();
    for (Class c = ob.getClass(); c != null; c = c.getSuperclass()) {
      for (Method method : c.getDeclaredMethods()) {
        if (method.getAnnotation(PostConstruct.class) != null) {
          System.out.println(c.getName() + "." + method.getName());
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given that: There seems to be no easy way to get a list of
Is there a way to get a list of all open sockets ( socket
Is there a way to get the list of currently running threads in objective-C?
Is there a way to get the list index name in my lapply() function?
Is there some way to get a distinct list of file extensions on all
I was wondering if there is a way to get a list of results
Is there a way to get all versions of list item(s) using a CAML
Is there a quick way to get a flattened List<TElement> from an ILookup<TKey, TElement>
Is there a way to get the previous item in a list , based
Is there a way using SWT to get a list of all processes currently

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.