Java – benefit from getters and setters generated in play! skeleton
Play for each public farm of the runtime model class! framework generates getters and setters.
public class Product { public String name; public Integer price; }
Will be transformed into
public class Product { public String name; public Integer price; public String getName() { return name; } public void setName(String name) { this.name = name; } public Integer getPrice() { return price; } public void setPrice(Integer price) { this.price = price; } }
The manual further explains:
Then, when you want to access a property, you can write:
product.name = "My product"; product.price = 58;
Which is converted to at load time:
product.setName("My product"); product.setPrice(58);
... and warn:
Because I can't use these getters and setters from outside play! I don't see any benefit from the project What are the benefits of public domain refactoring (encapsulating a domain and changing callers) compared to all modern ide considerations?
Solution
Short answer: beans need them
Longer: bean specifications require (among other things) getter / setter for each internal field I'm not 100% sure, but I think both hibernate and groovy templates want Java beans (POJO beans, not Java EE), so they will require getters / setters Playing just saves you time, so you don't have to worry about the boiler version code (unless you want to define your own getter / setter for some reason, you can do it)