Accessor Methods in Java

后端 未结 8 1356
野趣味
野趣味 2021-01-03 06:44

So I have a question on \"setter\" and \"getter\" methods and how useful they are or aren\'t.

Let\'s say I just write a very basic program like the following:

<
8条回答
  •  离开以前
    2021-01-03 07:34

    The advantage of using setters ans getters is that you can include rules for lazy initialization, validation, etc. Also, if you need to implement Java Beans complaint code, you need to follow those rules.

    Java Beans spec

提交回复
热议问题