Is there a way to know the inner classes that a Class has through Reflection in Java?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
Yes, use
Class#getDeclaredClasses()for this. You only need to determine if it’s an inner class or a nested (static) class by checking its modifiers. Assuming thatParentis the parent class, here’s a kickoff example:Note: this only doesn’t cover anonymous classes, but seeing your previous question on the subject, I don’t think you’re explicitly asking for them.