Java return the Object/modify the object (coding guidelines)

后端 未结 6 1034
野性不改
野性不改 2021-01-12 15:08

If a method populates/modifies an object, would it be preferable to return the object or to keep the return type as void and the method would modify the Object through its r

6条回答
  •  轮回少年
    2021-01-12 15:56

    The second one is less confusing to me, because it isn't clear from the first one if returned and passed objects are the same, and I don't find it normal to ignore a returned value.

提交回复
热议问题