7 ms·
> why accessor methods instead of making the fields public, but final. The best explanation I have is that it is: - a convention that seemed like a good idea
by skinkestek 5y ago
> why accessor methods instead of making the fields public, but final.
The best explanation I have is that it is:
- a convention that seemed like a good idea for many people at the time, it even has a name: Javabeans
- it allows for a standard non magic way to add logic to be run when reading or updating fields
- in a time where source control tools and Java refactoring tools where not as developed as they are today it made sense to make getters and setters everywhere since changing from public fields to accessor methods after it were already in use was probably scary for large teams.
- legerdemain 5y agoThanks for your speculation, but I'd rather take Brian Goetz's word for it. He is, after all, one of the architects of the Java language and the records feature in particular. ...Unless you're Brian Goetz's alt account?
- skinkestek 5y ago> Unless you're Brian Goetz's alt account? I have a policy of saying whether if is true or false. That said you should take his word for why it was designed that way and my word as an historical account of why I did that in 2005-2015.