private Map<String, Client> clients;
public Map<String, Client> getClients() {
return clients;
}
public void setClients(Map<String, Client> clients) {
this.clients = clients;
}
Kotlin's approach, where you declare and instantiate a property, and the getter/setter/backing storage are synthesized for you, is vastly preferable to me: public var clients = emptyMap<String, Client>()https://github.com/apache/solr/blob/main/solr/core/src/java/...
I'm a little surprised it was in literally the first place I looked, but I'm not surprised that it was easy to find. "Use private ivars and write getters and setters to encapsulate your state" was probably the second thing that a generation of CompSci students learned in their first programming class, right after "an object is an instance of a class."
Right at the top of the file...
> /* QueryParser.java / / Generated By:JavaCC: Do not edit this line. QueryParser.java */
I'm not claiming you're not going to see properties written out. I'm just saying that's not the majority of code you're going to see and to claim that idiomatic Java is all getters and setters is a bit far fetched.
Here is what I would consider modern idiomatic Java, immutable records and immutable classes that may expose some of their state:
https://github.com/jstachio/jstachio/blob/main/compiler/apt/... https://github.com/jstachio/jstachio/blob/main/compiler/apt/...
Setters are needed in exceedingly rarely circumstances.
Just saying, kotlin wasn't just a more aesthetically pleasing java, there were some deeper benefits as far as i can tell.