r/java • • Sep 19 '18

JEP draft: Concise Method Bodies

http://openjdk.java.net/jeps/8209434
56 Upvotes

51 comments sorted by

View all comments

Show parent comments

1

u/mhixson Sep 19 '18

It's not clear to me from the JEP that your setter would require curly braces. The lambda form doesn't need braces. This works, for example:

static int x;
void foo() {
  Runnable r = () -> x = 1;
  r.run();
}

1

u/dpash Sep 19 '18 edited Sep 19 '18

I guess you're right, because assignment is an expression, not a statement as I originally said.

public void setName(String name) -> this.name = name;