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

前端 未结 14 717
既然无缘
既然无缘 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:25

    Do what ever you like. After all getters and setters are just another public methods. You could use any other names.

    But if you use frameworks like Spring, you are bound to use those standard names and you should never put your custom codes inside them.

提交回复
热议问题