It is possible to obtain all fields with the method getDeclaredFields() of Class. Then you have to check the modifier of each fields to find the private ones:

List<Field> privateFields = new ArrayList<>();
Field[] allFields = SomeClass.class.getDeclaredFields();
for (Field field : allFields) {
    if (Modifier.isPrivate(field.getModifiers())) {
        privateFields.add(field);
    }
}

Note that getDeclaredFields() will not return inherited fields.

Eventually, you get the type of the fields with the method Field.getType().

Answer from Cyrille Ka on Stack Overflow
🌐
Baeldung
baeldung.com › home › java › core java › retrieve fields from a java class using reflection
Retrieve Fields from a Java Class Using Reflection | Baeldung
January 4, 2026 - So, we have protected and private fields that won’t be explicitly visible to other classes. Nevertheless, we can use the Class::getDeclaredFields method to get all declared fields.
🌐
Blogger
javarevisited.blogspot.com › 2012 › 05 › how-to-access-private-field-and-method.html
How to access Private Field and Method Using Reflection in Java? Example Tutorial
In our last Java tutorial on Reflection, we have seen how to call a method by its String name and we will use that information here for invoking the private method. Calling the private method using reflection is similar to accessing private fields reflectively. Use getDeclaredMethods(String name, Class · .. parameter) to get the declared private method. pass all ...
🌐
Jenkov
jenkov.com › tutorials › java-reflection › private-fields-and-methods.html
Java Reflection - Private Fields and Methods
April 9, 2018 - To access a private field you will need to call the Class.getDeclaredField(String name) or Class.getDeclaredFields() method. The methods Class.getField(String name) and Class.getFields() methods only return public fields, so they won't work.
🌐
Java2Blog
java2blog.com › home › core java › reflection › access private fields and methods using reflection in java
Access private fields and methods using reflection in java - Java2Blog
January 11, 2021 - ... Access private method Can you access private fields and methods using reflection? Yes, you can. It is very easy as well. You just need to call .setAccessible(true) on field or method object which you want to access. Class.getDeclaredField(String fieldName) or Class.getDeclaredFields() can ...
Find elsewhere
🌐
CodingTechRoom
codingtechroom.com › question › get-private-fields-java-reflection
How to Retrieve All Private Fields of a Class in Java Using Reflection - CodingTechRoom
This allows you to access private fields of a class and determine their types at runtime. ... import java.lang.reflect.Field; public class Main { public static void main(String[] args) { try { Class<?> clazz = SomeClass.class; Field[] fields = clazz.getDeclaredFields(); // Get all fields including private ones for (Field field : fields) { // Check if the field is private if (java.lang.reflect.Modifier.isPrivate(field.getModifiers())) { System.out.println("Field Name: " + field.getName() + ", Type: " + field.getType().getSimpleName()); } } } catch (Exception e) { e.printStackTrace(); } } }
🌐
CodingTechRoom
codingtechroom.com › question › retrieve-java-class-fields
How to Retrieve All Class Fields in Java, Including Private and Inherited Fields - CodingTechRoom
private void listAllFields(Object obj) { List<Field> fieldList = new ArrayList<>(); Class<?> tmpClass = obj.getClass(); while (tmpClass != null) { fieldList.addAll(Arrays.asList(tmpClass.getDeclaredFields())); tmpClass = tmpClass.getSuperclass(); } // Process fieldList as needed } In Java, accessing class fields can be crucial for reflection tasks, especially when you need to examine all fields, including those that are private or inherited.
🌐
C# Corner
c-sharpcorner.com › UploadFile › 433c33 › accessing-private-fields-and-private-methods-hacking-a-clas
Accessing Private Fields and Private Methods (Hacking a Class) in Java
October 11, 2019 - The first one is Class.getDeclareMethod(String obj, Class[] parameter types ) and the second is Class.getDeclareMethods( ). Both of the methods only return public Methods, so they would not work.
🌐
GeeksforGeeks
geeksforgeeks.org › java › how-to-access-private-field-and-method-using-reflection-in-java
How to Access Private Field and Method Using Reflection in Java? - GeeksforGeeks
February 5, 2021 - Java Collection · Last Updated : 5 Feb, 2021 · If we want to access Private Field and method using Reflection we just need to call setAccessible(true) on the field or method object which you want to access. Class.getDeclaredField(String fieldName) ...
🌐
Vultr Docs
docs.vultr.com › java › examples › access-private-members-of-a-class
Java Program to Access private members of a class | Vultr Docs
December 11, 2024 - Use the setter and getter methods to access the private field. ... public class Main { public static void main(String[] args) { Person person = new Person(); person.setName("John"); System.out.println("Name: " + person.getName()); } } Explain ...
🌐
Programiz
programiz.com › java-programming › examples › access-private-members
Java Program to Access private members of a class
Become a certified Java programmer. Try Programiz PRO! ... class Test { // private variables private int age; private String name; // initialize age public void setAge(int age) { this.age = age; } // initialize name public void setName(String name) { this.name = name; } // access age public int getAge() { return this.age; } // access name public String getName() { return this.name; } } class Main { public static void main(String[] args) { // create an object of Test Test test = new Test(); // set value of private variables test.setAge(24); test.setName("Programiz"); // get value of private variables System.out.println("Age: " + test.getAge()); System.out.println("Name: " + test.getName()); } }
🌐
Coderanch
coderanch.com › t › 373499 › java › reflection-fields-public
Using reflection to get ALL fields, not just public ones (Java in General forum at Coderanch)
Also it's possible to get at the info in the private field using reflection, or if the class is Serializable you can write it to a file and see that the file contains data from private superclass fields. However these fields are still not considered accessible in the sense that you can access them by simply wrting the name of the field like you can for most other fields.