by kentosi · 9y ago · 0 comments
I currently use Java for work and I cry a little inside every time I see big hashCode() methods, toString() methods and a chain of getXXX()/setXXX() methods when I know that a simple case class statement would have been all that was needed.
final class Data() {
final int id;
final String name;
public Data(int id, String name) {
this.id = id;
this.name = name;
}
}
No need for getter/setter.
Still not as good as the scala one tought, but probably a little bit faster since it does not use accessor methods.P.S.: I'm a scala user.
case class Data(id: Int, name: String)
and comes with all the other things merb mentioned. And it's unlikely to be any slower in practice since the JIT can inline the access (not that method calls are ever likely to be a noticeable overhead anyway).