Variable and method naming conventions for boolean verbs in Java?

Tn Hn :

I know that many suggest this convention:

boolean deleted;
boolean isDeleted();

But what do you do when you want to name a boolean to indicate that a user can leave?

boolean userCanLeave
boolean isUserCanLeave()

boolean canUserLeave
boolean isCanUserLeave()

boolean userLeave
boolean isUserLeave()

boolean userLeave
boolean canUserLeave()

I'm not sure if there is any standard for this or do you just take the one you think is most readable? It is the variable to getter method name mapping that is interesting here.

Am_I_Helpful :

You should use a better variable name like userAllowedToLeave.

And, then use the getter method as isUserAllowedToLeave().

This at least uses the "is" getter, and sounds grammatically correct too.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=454830&siteId=1