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
?
views:
47answers:
1
+7
A:
It should be isShowLabels
weird as that may sound, that's the convention. You could always rename the boolean to showingLabels
.
Adam
2010-10-21 23:29:05
+1, and more importantly than that it's convention, it's also *required* if you want to use classes like `Introspector`.
Kirk Woll
2010-10-21 23:31:38
additionally, if using Eclipse, it can generate it for you.
SB
2010-10-21 23:31:39
Thank you. I will probably rename the field to showingLabels, and have `setShowingLabels` and `isShowingLabels`.
alpha123
2010-10-21 23:36:05
@alpha123 - Glad to help! If you like the answer click the checkmark to mark it as correct.
Adam
2010-10-21 23:41:42
Follow the convention, when when it sucks :-) Will save time and pain later.
Tony Ennis
2010-10-21 23:45:19
@adam it said I had to wait 5 minutes. I waited, and now have.
alpha123
2010-10-21 23:48:05