While this will make getters much concise, it won't help much with setters, because they're a statement.
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
would become
private String name;
public String getName() -> name;
public void setName(String name) -> this.name = name;
I'm curious to see how their introduction in C# changed the language. My initial feeling is that the usefulness of this change might be of limited scope, if only because only the most basic of methods would benefit from this.
Edit: I originally had the following setter
public void setName(String name) -> { this.name = name; }
From what I remember of the data class document, the fields don't quite have public access, but can be accessed like they do. I think it was possible to create a custom setter or getter if you need to customise it.
10
u/dpash Sep 19 '18 edited Sep 19 '18
While this will make getters much concise, it won't help much with setters,
because they're a statement.would become
I'm curious to see how their introduction in C# changed the language. My initial feeling is that the usefulness of this change might be of limited scope, if only because only the most basic of methods would benefit from this.
Edit: I originally had the following setter
but it was pointed out I had needless braces.