Is it bad practice to have my getter method change the stored value?

前端 未结 14 720
既然无缘
既然无缘 2020-12-29 02:08

Is it bad practice to change my getter method like version 2 in my class.

Version 1:

 public String getMyValue(){
     return this.myValue
 }
         


        
14条回答
  •  我在风中等你
    2020-12-29 02:33

    I do feel this is a bad practice unless and until you explain the reason why it is so necessary for you modify the object inside the getter method instead of doing it inside the setter method.
    Do you feel this cannot be done for some reason? Could you please elaborate?

提交回复
热议问题