public class MyClass {
ClassABC abc = new ClassABC();
}
I just have a .class file of ClassABC. I want to print all the public, private, protected and default field values of “abc” object. How can I do this using Reflection?
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.
You can get all fields by
Class#getDeclaredFields(). Each returns aFieldobject of which you in turn can use theget()method to obtain the value. To get the values for non-public fields, you only need to setField#setAccessible()totrue.So, in a nut:
See also: