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

前端 未结 7 890
深忆病人
深忆病人 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:36

    I want to point a different view on this general naming convention, e.g.:

    see java.util.Set: boolean add​(E e)

    where the rationale is:

    do some processing then report whether it succeeded or not.

    While the return is indeed a boolean the method's name should point the processing to complete instead of the result type (boolean for this example).

    Your createFreshSnapshot example seems for me more related to this point of view because seems to mean this: create a fresh-snapshot then report whether the create-operation succeeded. Considering this reasoning the name createFreshSnapshot seems to be the best one for your situation.

提交回复
热议问题