Java features
Tom Rosenfeld
tom.rosenfeld at gmail.com
Sat Jun 10 05:46:48 UTC 2023
Hello Everyone,
I hope this is an appropriate forum for the thoughts I'd like to share on
Java. If not, I would appreciate guidance as to the most fitting venue for
such a discussion.
Currently, I am contemplating two main points related to programming
languages, specifically in relation to Java. First, it seems that many
languages frequently adopt features from each other, and I'm curious as to
why Java hasn't taken a similar approach.
In particular, I've been considering the potential benefits of integrating
extension methods and async-await into Java. With extension methods, users
could benefit from a more concise syntax and a more functionally expressive
coding approach. The async-await feature, a staple in languages like C# or
JavaScript, might even be a superior alternative to Structured Concurrency.
For instance, consider the code in this post:
https://www.infoq.com/news/2023/06/structured-concurrency-jdk-21/
In C#, it might look something like this:
public async Task<Response> HandleAsync() {
Task<string> userTask = FindUserAsync();
Task<int> orderTask = FetchOrderAsync();
await Task.WhenAll(userTask, orderTask);
return new Response(userTask.Result, orderTask.Result);
}
In comparison to the original, this version seems considerably shorter,
clearer, and easier to read.
I look forward to hearing your thoughts on this matter.
Best,
Tom
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/java-se-spec-comments/attachments/20230610/1e32843f/attachment.htm>
More information about the java-se-spec-comments
mailing list