简体   繁体   English

Java方法命名约定

[英]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应该是isShowingLabelsisShowLabels (那真是奇怪的声音),还是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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM