views:

47

answers:

1

I have a boolean field called showLabels in a Bean class, and I want to provide getter and setter methods for it. The setter will be setShowLabels, but should the getter be isShowingLabels, isShowLabels (that's really weird sounding), or setShowLabels?

+7  A: 

It should be isShowLabels weird as that may sound, that's the convention. You could always rename the boolean to showingLabels.

Adam
+1, and more importantly than that it's convention, it's also *required* if you want to use classes like `Introspector`.
Kirk Woll
additionally, if using Eclipse, it can generate it for you.
SB
Thank you. I will probably rename the field to showingLabels, and have `setShowingLabels` and `isShowingLabels`.
alpha123
@alpha123 - Glad to help! If you like the answer click the checkmark to mark it as correct.
Adam
Follow the convention, when when it sucks :-) Will save time and pain later.
Tony Ennis
@adam it said I had to wait 5 minutes. I waited, and now have.
alpha123