You should pass the object to get method of the field, so

  import java.lang.reflect.Field;

  Field field = object.getClass().getDeclaredField(fieldName);    
  field.setAccessible(true);
  Object value = field.get(object);
Answer from Dmitry Spikhalsky on Stack Overflow
🌐
DigitalOcean
digitalocean.com › community › tutorials › java-reflection-example-tutorial
Java Reflection Example Tutorial | DigitalOcean
August 3, 2022 - If the field is final, the set() methods throw java.lang.IllegalAccessException. We know that private fields and methods can’t be accessible outside of the class but using reflection we can get/set the private field value by turning off the java access check for field modifiers.
🌐
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 - // Access Private Field Using Reflection in Java import java.lang.reflect.Field; // Student class declaration class Student { // private fields private String name; private int age; // Constructor public Student(String name, int age) { this.name = name; this.age = age; } // Getters and setters public String getName() { return name; } public void setName(String name) { this.name = name; } private int getAge() { return age; } public void setAge(int age) { this.age = age; } // Override toString method to get required // output at terminal @Override public String toString() { return "Employee [nam
🌐
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 - Of course, we could use the getDeclaredFields() method on both Person and Employee classes and merge their results into a single array. But what if we don’t want to specify the superclass explicitly?
🌐
Baeldung
baeldung.com › home › java › core java › get all record fields and its values via reflection
Get All Record Fields and Its Values via Reflection | Baeldung
January 16, 2024 - However, the problem can be solved without using the new RecordComponent class. Java reflection API provides the Class.getDeclaredFields() method to get all declared fields in the class.
🌐
Coderanch
coderanch.com › t › 378770 › java › reflection-final-static-field
Using reflection to get the value of a final static field (Java in General forum at Coderanch)
January 5, 2006 - In order to do this it needs to call the stored procedure with parameters extracted from an xml file. I've given each parameter an attribute sqltype which should take the name of one of the fields of java.sql.Types and then I'm using reflection to get the actual value of that field.
🌐
noredhomepage
noredhomepage.weebly.com › java-reflection-get-field-value-from-object.html
Java reflection get field value from object - noredhomepage
In order to access a private field ... of a public field, you can call the get() method of the Field object, with the object featuring the field value that you'd like to get as the first parameter....
🌐
Oracle
docs.oracle.com › javase › tutorial › reflect › member › fieldValues.html
Getting and Setting Field Values (The Java™ Tutorials > The Reflection API > Members)
The Book class illustrates how to set the values for long, array, and enum field types. Methods for getting and setting other primitive types are described in Field. import java.lang.reflect.Field; import java.util.Arrays; import static java.lang.System.out; enum Tweedle { DEE, DUM } public class Book { public long chapters = 0; public String[] characters = { "Alice", "White Rabbit" }; public Tweedle twin = Tweedle.DEE; public static void main(String...
Find elsewhere
🌐
Bala's Blog
dkbalachandar.wordpress.com › 2017 › 03 › 08 › how-to-use-reflectionutils-to-retrieve-the-field-value
How to use ReflectionUtils to retrieve the field value | Bala's Blog
March 8, 2017 - import org.apache.commons.lang3.exception.ExceptionUtils; import org.apache.commons.lang3.reflect.FieldUtils; import java.lang.reflect.Field; public class ReflectionUtilsMain { public static void main(String[] args) { Employee employee = new Employee(); employee.setEmpId("1234"); employee.setFirstName("John"); employee.setLastName("Turner"); employee.setDesignation("Manager"); System.out.println(employee); //Now you want to access the First Name from Employee object with Java reflection String firstName = null; String fieldName = "firstName"; for (Class aClass = employee.getClass(); aClass !=
🌐
Coderanch
coderanch.com › t › 443479 › java › Property-Field-Reflection
get Property-Field-Name via Reflection (Java in General forum at Coderanch)
April 30, 2009 - The answer is that there doesn't have to be any such field, by any name, so reflection cannot help you. For example, getX() might look like Even if the method returns a variable, it might be named "variableX" or "valueOfX" or anything; or it might be an element of an array, or a value in a HashMap, or a variety of other things. If you need to find this out about one particular class, you can disassemble it with the "javap" tool and look at the bytecode to see how the method is implemented.
🌐
Jaketrent
jaketrent.com › post › use-java-reflection-get-field-w-accessor
Use Java Reflection to Get Field w/ Accessor
The only stipulation to this working is that the class follows the JavaBean naming convention standard of "get" + capitalized field name following. Oh, and one more: this is only designed for @Entity's with one @Id field (no composite key). This method goes through all fields, finds the one with the javax.persistence.Id interface annotation, then tries to find a matching accessor method. If it is found, it is executed, the value of the id field is given, finally to be used to create the specially formatted string.
🌐
TutorialsPoint
tutorialspoint.com › javareflect › javareflect_field_get.htm
java.lang.reflect.Field.get() Method Example
The java.lang.reflect.Field.get(Object obj) method returns the value of the field represented by this Field, on the specified object. The value is automatically wrapped in an object if it has a primitive type.
🌐
Google Groups
groups.google.com › g › scala-user › c › DT1Ifw8YKvU
how to get value class fields with scala reflection
April 3, 2013 - It looks like that when using runtime reflection, foo becomes the int value (3) because it extends AnyVal. ... This behavior is expected or are we using the reflection API in a wrong way? I get the same result using SMirror: scala> implicit val mirror = scala.reflect.runtime.currentMirror · mirror: reflect.runtime.universe.Mirror = JavaMirror with scala.t...
🌐
Oracle
forums.oracle.com › ords › apexds › post › reflection-exception-by-setting-a-field-value-7376
[Reflection] Exception by setting a field value - Oracle Forums
June 24, 2015 - Hi all!I didn't work a lot with Reflection and now I'm having troubles by writing a method to set a field value of an unknown type.I wrote a little example program to show, where I cannot find a solut...
🌐
GitHub
gist.github.com › 4097fe16517d94b1f455
Java Field Reflection - Getting non-null fields value using reflection · GitHub
Java Field Reflection - Getting non-null fields value using reflection - JavaFieldReflection.java
🌐
W3Docs
w3docs.com › java
Reflection generic get field value
To get the value of a generic field using reflection in Java, you can use the get() method of the Field class, which returns the value of the field as an Object.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › reflect › Field.html
Field (Java Platform SE 8 )
2 weeks ago - Gets the value of a static or instance boolean field. ... IllegalAccessException - if this Field object is enforcing Java language access control and the underlying field is inaccessible.
🌐
Java Code Geeks
javacodegeeks.com › home › core java
How to Retrieve String Fields with Java Reflection - Java Code Geeks
September 2, 2025 - Using ReflectionUtil to get lastName generically. ... Public field value: Tom-Public Private field value: Tom-Private Private field via generic utility: Tom-Private · This confirms that reflection can access both public and private fields, although the approach differs depending on the field’s visibility. This article demonstrated how to use reflection to retrieve String field values from Java objects.
🌐
Jenkov
jenkov.com › tutorials › java-reflection › fields.html
Java Reflection - Fields
April 21, 2016 - Once you have obtained a Field reference you can get and set its values using the Field.get() and Field.set()methods, like this:
🌐
Coderanch
coderanch.com › t › 553275 › java › read-string-java-reflection
how to read string value using java reflection [Solved] (Beginning Java forum at Coderanch)
I am setting string(model class string) value in my service class i want to get this in my model class to do compare operation. In model class trying to get using reflection.