In code example, the returned object from nameField.get(maria) needs to be cast to String · Issue #283 · java/devjava-content
Repository navigation
In code example, the returned object from nameField.get(maria) needs to be cast to String #283
New issue
New issue
Open
Open
In code example, the returned object from nameField.get(maria) needs to be cast to String #283
Description
@authentictech's profile authentictech opened on Oct 2, 2026In Learn Java > Mastering the API Reflection and Method Handles > The Reflection API > Reading and Writing Fields, section Getting and Setting Field Values , there needs to be a cast in order to avoid the error "incompatible types: Object cannot be converted to String".
So,
String name = nameField.get(maria);
needs to be
String name = (String) nameField.get(maria);