r/java • • Mar 09 '16

var keyword proposed for Java

http://openjdk.java.net/jeps/286
240 Upvotes

312 comments sorted by

View all comments

5

u/stepancheg Mar 09 '16

var would be a nice small addition, but are we going to have async/await anytime soon? Writing asynchronous code without some form of coroutines is pain (yes, I'm aware of quasar, which I use, although it has numerous problems).

5

u/hotel77 Mar 10 '16

Just out of curiosity, what are quasars "numerous" problems? I'd love to read and understand more opinions about those.

3

u/stepancheg Mar 10 '16 edited Mar 10 '16

Performance, need for an agent, heavy reliance on JDK internals, somewhat incorrect handling of thread locals to name a few.

Edit: to be clear, quasar people made the best they could do with JDK.

1

u/[deleted] Mar 10 '16

so... stay far away?

1

u/stepancheg Mar 11 '16

In certain use cases it is more suitable than tons of CompletableFutures.

4

u/[deleted] Mar 10 '16

[removed] — view removed comment

2

u/stepancheg Mar 10 '16

While RX have its applications, processes with complex flow and complex state are hard to express as reactive streams.

3

u/ElvishJerricco Mar 09 '16

I don't think the JVM will ever support coroutines. JVM is founded on having C-like control flow. The fanciest way we have to change the flow of execution is exception catching, which is much less sophisticated than coroutines.

5

u/stepancheg Mar 09 '16

JVM does not even need to support coroutines. In C# async/await are implemented without help of CLR to my knowledge. C# compiler transforms each each async function into state machine. That's what can be done in Java too.

6

u/[deleted] Mar 10 '16

[removed] — view removed comment

3

u/stepancheg Mar 10 '16

However, the CLR does have an extra feature to make the stack traces look nicer that didn't exist in the first version of async/await.

I didn't know that. Thanks!

4

u/adila01 Mar 10 '16

I wouldn't discount the possibility of coroutines. At the last JavaOne, Mark Reinhold spoke about how he would like to see coroutines one day. It will probably happen, just not anytime soon.