Property Access Methods

The methods used for getting and setting property values should conform to the standard design pattern for properties. These methods may throw checked exceptions. The method signatures are as follows:

public void set<PropertyName>(<PropertyType> value);
public <PropertyType> get<PropertyName>();

The existence of a matching pair of methods that conform to this pattern represents a read/write property with the name <PropertyName> of the type <PropertyType>. If only the get() method exists, the property is considered to be read-only, and if only the set() method exists the property is considered to be write-only. If the <PropertyType> is boolean, the get() method can be replaced or augmented with a method that uses the following signature:

public boolean is<PropertyName>();

Get Developing Java Beans now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.