r/java Sep 19 '18

JEP draft: Concise Method Bodies

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

51 comments sorted by

View all comments

6

u/_INTER_ Sep 20 '18

I always thought that Java's code readability code was rather nice. Mainly because the structure of classes, methods, many control structures always remain the same visually. You can usually scan a class easily without much interruption. It's modifier, return type / void method name, parameters, brace, body, brace.

Now this feature completely destroys that. It adds new syntax without much gain. The languages keeps on adding and bloating, like C++ and C#.

2

u/lukaseder Sep 20 '18

If that's what you think, then you will like the idea that soon empty class bodies can be replaced by semi colons. Instead of:

class A {}

Just write

class A;

2

u/lbkulinski Sep 20 '18

That reminds me of a forward declaration in C++ 😖

2

u/Bobby_Bonsaimind Sep 21 '18

Give me a moment, I'll try to figure out if I could care less... ... ...nope, sorry.

0

u/_INTER_ Sep 20 '18

what, when, why?

2

u/lukaseder Sep 20 '18

See e.g. http://cr.openjdk.java.net/~briangoetz/amber/datum.html

interface Node { }

abstract record BinaryOpNode(Node left, Node right) 
    implements Node;

record PlusNode(Node left, Node right) 
      extends BinaryOperatorNode(left, right);

record MulNode(Node left, Node right) 
      extends BinaryOperatorNode(left, right);

record IntNode(int constant) implements Node;

And also: http://hg.openjdk.java.net/amber/amber/rev/727ca44aff68, https://twitter.com/jeffreymaxwell/status/984079813941125120

I've never seen a formal specification, though. Seems like a simple "under the hood" change to the JLS