[英]Java method naming conventions
I have a boolean field called showLabels
in a Bean class, and I want to provide getter and setter methods for it. 我在Bean类中有一个名为
showLabels
的布尔字段,我想为它提供getter和setter方法。 The setter will be setShowLabels
, but should the getter be isShowingLabels
, isShowLabels
(that's really weird sounding), or setShowLabels
? setter将是
setShowLabels
,但是getter应该是isShowingLabels
, isShowLabels
(那真是奇怪的声音),还是setShowLabels
?
It should be isShowLabels
weird as that may sound, that's the convention . 它应该是
isShowLabels
因为这听起来很奇怪, 这就是惯例 。 You could always rename the boolean to showingLabels
. 您始终可以将布尔值重命名为
showingLabels
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.