O'Reilly logo

Java™ Phrasebook by Timothy Fisher

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Setting Field Values

String newTitle = "President";
											Class c = someObject.getClass();
											Field titleField = c.getField("title");
											titleField.set(someObject, newTitle);

In order to set a field value, you must first get a Field object for the field you want to set the value of. See the phrase “Discovering Class Fields” in this chapter for more information about getting Field objects from a class. You should also refer to the phrase “Getting Field Values” also contained in this chapter for more information about getting field values.

The Field class has specialized methods for setting the values of primitive types. Methods such as setInt(), setFloat(), and setByte() allow you to set the values of the primitive types. For complete details of the set ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required