Naming conventions for java methods that return boolean(No question mark)

前端 未结 7 907
深忆病人
深忆病人 2020-12-02 10:49

I like using question mark at the end of method/function names in other languages. Java doesn\'t let me do this. As a workaround how else can I name boolean returning method

7条回答
  •  鱼传尺愫
    2020-12-02 11:31

    I want to post this link as it may help further for peeps checking this answer and looking for more java style convention

    Java Programming Style Guidelines

    Item "2.13 is prefix should be used for boolean variables and methods." is specifically relevant and suggests the is prefix.

    The style guide goes on to suggest:

    There are a few alternatives to the is prefix that fits better in some situations. These are has, can and should prefixes:

    boolean hasLicense();
    boolean canEvaluate();
    boolean shouldAbort = false;
    

    If you follow the Guidelines I believe the appropriate method would be named:

    shouldCreateFreshSnapshot()
    

提交回复
热议问题