Java setting private fields inside constructors

前端 未结 10 775
独厮守ぢ
独厮守ぢ 2021-01-17 15:48

Common design practice is to make instance variables private and have public getters and setters to access them. But many times I have seen code samples on the internet that

10条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-17 15:59

    Sometimes when you would want make the class immutable, it is just one of the things you need to do. And don't have setter methods at all in that case.

提交回复
热议问题