Reputation: 2748
Question : Which are methods using JavaBeans naming conventions for accessors and mutators?
The code above was one of the correct answer:
public getNumWings() {return numberWings;}
I checked the beans definition (section 8.3 clarify a little more) and from what I read (and knew) I would say the getter has a wrong name, Is this answer really correct? If it is, is because a new property "numWings" is "created/exposed"?
Upvotes: 2
Views: 925
Reputation: 77167
The JavaBeans specification is concerned with properties, not fields. Although it's common for properties to be backed by simple fields with the same names, there's no requirement to do so, and a number of properties (particularly booleans such as isEmpty()
) are often computed on the fly.
In this example, the getNumWings()
accessor is a getter for a property named numWings
, and there's no problem. The fact that the property is backed by a field with a different name is a private implementation detail and irrelevant as far as the bean interface is concerned.
Upvotes: 3