Java getter and setter methods become properties in Gosu
For methods on Java types that look like getters and setters, Gosu exposes methods on the type as properties rather than methods. Gosu uses the following rules for methods on Java types:
- If the method name starts with
setand takes exactly one argument, Gosu exposes this method as a setter for the property. The property name matches the original method but without the prefixset. For example, suppose the Java method signature issetName(String thename). Gosu exposes this method as a property set function for the property namedNameof typeString. - If the method name starts
with
getand takes no arguments and returns a value, Gosu exposes this method as a getter for the property. The property name matches the original method but without the prefixget. For example, suppose the Java method signature isgetName()and it returns aString. Gosu exposes this method as aproperty getfunction for the property namedNameof typeString. - If the method name starts
with
is, takes no arguments, and returns a Boolean value, the rules are similar to the rules forget. Gosu exposes this method as a getter for the property. The property name matches the original method but without the prefixis. For example, suppose a Java method signature isisVisible(). Gosu exposes this method as aproperty getfunction for a Boolean property namedVisible.
If the Java code has a setter and a getter, Gosu makes the property readable and writable. If the setter is absent, Gosu makes the property read-only. If the getter is absent, Gosu makes the property write-only.
For example, consider a Java class called
Circle with the following
method declarations:
public double getRadius()
public void setRadius(double dRadius)
Gosu exposes these methods as the Radius property, which is readable
and writable. With this property, you can use straightforward code such
as:
circle.Radius = 5 // Property SET
print(circle.Radius) // Property GET
See also
