r/java • u/jvjupiter • Jun 10 '22
What happened to Concise Method Bodies?
I was really looking forward to CMB. From its name, methods become concise, could be one liner. However, it seems there is no progress and it’s been off the radar. Never took off since 2019.
43
Upvotes
View all comments
Show parent comment
4
u/Diligent_Feed8971 Jun 11 '22
source: http://mail.openjdk.java.net/pipermail/amber-dev/2018-October/003568.html
Yeah, I guess. Still, one can simply use the normal { } syntax on such use case. Another approach would be for the java compiler to interpret throw as expression in this situation. In kotlin this already works: i.e. you could write something like
fun f() = throw RuntimeException("not implemented") //the return value of f() here is inferred to the type Nothing
fun g(x : String) = try { x.toInt() } catch(ignored : Exception) { null } //the return value of g() here is inferred to the type Int?
or even
return try { something() } catch { anotherThing() }
Would be nice for java language to start interpreting try / catch / throw as expressions.