user1366028
user1366028

Reputation: 41

Renaming class - field value in Java

Hey I need change uuid value via getClass(), here is my code but I don't know what obiect I must type instead UUID

Field uuidField = c.getClass().getDeclaredField("uuid");
uuidField.setAccessible(true);
uuidField.set(UUID, newUuidValue);

Upvotes: 0

Views: 66

Answers (2)

Jon Skeet
Jon Skeet

Reputation: 1499770

If you want the equivalent of

c.uuid = newUuidValue;

but with reflection, you just want:

uuidField.set(c, newUuidValue);

The first argument to set is a reference to the object whose field you want to modify.

Upvotes: 2

Peter Lawrey
Peter Lawrey

Reputation: 533442

You have to give the instance whose field you want to change which is most likely c.

Upvotes: -1

Related Questions