TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Java 21 makes me like Java again

412 点作者 wscp-dev超过 1 年前

29 条评论

northern-lights超过 1 年前
The biggest feature in Java 21 is the release of Virtual Threads: <a href="https:&#x2F;&#x2F;openjdk.org&#x2F;jeps&#x2F;444" rel="nofollow noreferrer">https:&#x2F;&#x2F;openjdk.org&#x2F;jeps&#x2F;444</a><p>For some reason, this is missing from the article. If there was any feature that would sway existing Golang developers to switch to Java, it would be this. It would perhaps also convince the haters of the reactive-style concurrency patterns.
评论 #37539937 未加载
评论 #37541621 未加载
评论 #37540751 未加载
评论 #37539402 未加载
评论 #37539669 未加载
评论 #37541893 未加载
评论 #37541496 未加载
评论 #37539426 未加载
评论 #37541501 未加载
评论 #37545894 未加载
评论 #37541705 未加载
评论 #37539365 未加载
评论 #37543309 未加载
评论 #37541945 未加载
评论 #37544540 未加载
评论 #37540471 未加载
评论 #37541193 未加载
msgilligan超过 1 年前
The title of the blog post is IMO a poor choice. The (hidden) subtitle of the post is &quot;Algebraic data types in Java&quot; which is much more descriptive of the content. A better title would have been &quot;Algebraic data types in Java 21&quot;.<p>Perhaps because of the title, many&#x2F;most of the comments here are off-topic. I was hoping to see more discussion about algebraic data types, strengths and weaknesses of the Java implementation, technical comparisons to other languages, etc.
评论 #37545284 未加载
评论 #37545618 未加载
adrianmsmith超过 1 年前
The &quot;Sealed classes&quot; feature, as described here, just feels all wrong to me.<p>They are saying that if you have a (normal) interface, anyone can create a new class implementing it. So if you do<p><pre><code> if (x instanceof Foo) { ... } else if (x instanceof Bar) { ... } ... </code></pre> then your code will break at runtime if someone adds a new class, as that code won&#x27;t expect it. So the article is saying the solution is to use the new &quot;sealed&quot; interfaces feature, so nobody can create any new classes implementing that interface, and your &quot;if&quot; statement will not break.<p>Surely object-oriented programming already thought about that and already solved that? (I know object-oriented programming is out of vogue at the moment, but Java <i>is</i> an object-oriented language.)<p>The solution there is to add a method to the interface, and all your classes implement that. Then rather than having a massive if&#x2F;switch statement with all the options, you call the method.<p>That is better than preventing people from extending your code, it <i>allows</i> them to extend your code. They just have to implement the method. And the compiler will force them to do that, so they can&#x27;t even accidentally forget.<p>The example given of color spaces (RGB, CMYK etc.) is a great example. I can absolutely imagine writing code which uses color spaces, but then some user or client having a need to use a weird obscure color space I haven&#x27;t thought of. I wouldn&#x27;t want to restrict my code to saying &quot;these are the color spaces I support, due to this massive if&#x2F;switch statement listing them all, the code is written in such a way that you can&#x27;t extend it&quot;.
评论 #37544461 未加载
评论 #37542820 未加载
评论 #37544376 未加载
评论 #37543353 未加载
评论 #37542805 未加载
kaashif超过 1 年前
Nice article as someone familiar with sum types but not sum types in Java.<p>I don&#x27;t know if sum types alone are enough to get me to like Java, pervasive nullability is still around and even rears its head multiple times in this article.
评论 #37539198 未加载
评论 #37541962 未加载
评论 #37538996 未加载
aranchelk超过 1 年前
&gt; Why do we call them product types anyway?<p>Answer in the piece is not wrong, but put more intuitively and succinctly: the total number of possible value (inhabitants) in a product type is the product of the quantity of inhabitants of the constituent types.<p>Replace the “product”s with “sum”s and it works too.<p>Interestingly, the total number of unique functions (judged only in terms of input and output) from a -&gt; b can be found by exponentiation, (inhabitants of b) ^ (inhabitants of a).
评论 #37542451 未加载
评论 #37547363 未加载
评论 #37541981 未加载
logicchains超过 1 年前
I can&#x27;t wait &#x27;til Project Valhalla is complete and Java finally gets value types. Then with sum types, value types and goroutines it&#x27;ll be one of the nicest languages out there.
dzonga超过 1 年前
java was never really a bad language.<p>the people were. if not massive over-engineering. too many abstract concepts that make it hard to grasp a codebase.<p>code voodoo - in the form of reverse GOTO statement i.e annotations<p>DI frameworks .<p>what needs fixing is not the language but the ecosystem. there needs to be a &quot;reformation&quot; movement within the java ecosystem.<p>yeah people migrating to kotlin or clojure or scala isn&#x27;t enough.
评论 #37547835 未加载
fooyc超过 1 年前
The author cites this to justify the need for Records:<p>&gt; Most Java objects set every field to be private and make all fields accessible only through accessor methods for reading and writing.<p>&gt; Unfortunately, there are no language enforced conventions for defining accessors; you could give the getter for foo the name getBar, and it’ll still work fine, except for the fact that it would confuse anybody trying to access bar and not `foo&#x27;.<p>Scala supports pattern matching on objects implementing the `unapply` method.<p>Is this considered harmful? Why didn’t Java follow this route?
评论 #37582758 未加载
YetAnotherNick超过 1 年前
Java was always a great language. It&#x27;s the enterprisy ecosystem that make me want to throw up. To implement a line of logic, I have seen dozen classes and interfaces.
earthboundkid超过 1 年前
道生一,一生二,二生三,三生萬物。萬物負陰而抱陽,沖氣以為和。<p>The Function gives birth to the Unit type. The Unit type gives birth to the Boolean. The Boolean gives birth to the Value type. The Value type gives birth to the Top type. Each Top type contains 0s and 1s, thereby bringing harmony to the computation.
truth_seeker超过 1 年前
Golang is simple, smart and opinionated subset of Java&#x2F;C#.<p>Everything moves slowly in corporate world. It will take another at least 2-3 years for large community of Java ecosystem and average devs to adopt Java 21 and capabilities.
评论 #37547437 未加载
jjtheblunt超过 1 年前
Is there any widespread concern over lack of unsigned int native types?
评论 #37547414 未加载
pharmakom超过 1 年前
the argument for Java seems to be that it&#x27;s gradually gaining features we already have in Scala, Kotlin, OCAML, F#, etc... so why not use the languages that have those features today?
评论 #37545438 未加载
评论 #37545168 未加载
评论 #37548139 未加载
andrea76超过 1 年前
I hate Java because the docker containers based on it take too much RAM. The smallest Spring JAR takes about 70-120 MB for a single container!
评论 #37548576 未加载
ahurmazda超过 1 年前
My favorite go feature (not exclusive to go) is `implicit` interface. Once I drank from that cup there is no going back!
michaelcampbell超过 1 年前
What a weird title change.
评论 #37582771 未加载
billfruit超过 1 年前
Does it add value types?
评论 #37541858 未加载
jjtheblunt超过 1 年前
Is there an Ocaml vatiant for the JVM (similar to F# for dotnet)?
评论 #37539644 未加载
评论 #37541697 未加载
评论 #37539659 未加载
mathisfun123超过 1 年前
any advice on a book&#x2F;tut to learn &quot;modern&quot; java?
评论 #37544508 未加载
评论 #37544406 未加载
acheron超过 1 年前
In other news, we have an upgrade path at work to go from Java 8 to Java 11 pretty soon.
评论 #37539499 未加载
评论 #37539145 未加载
评论 #37543545 未加载
评论 #37539044 未加载
评论 #37541288 未加载
评论 #37541948 未加载
评论 #37539460 未加载
评论 #37541420 未加载
neonsunset超过 1 年前
Sad this gets to front page while a blog post which documents that .NET 8 has 200 A4 pages worth of performance improvements gets absolutely ignored.<p>C# keeps being the language people are looking for but don&#x27;t know about.
评论 #37541421 未加载
评论 #37542216 未加载
评论 #37542291 未加载
评论 #37541316 未加载
评论 #37544577 未加载
评论 #37541361 未加载
评论 #37542649 未加载
评论 #37541308 未加载
评论 #37541652 未加载
评论 #37544253 未加载
评论 #37541417 未加载
insanitybit超过 1 年前
The problems with Java can&#x27;t be fixed by adding new things, you can&#x27;t undo decades of ecosystem development, training, and ideology built on top of the idea that inheritance is really good idea and belongs everywhere.<p>edit: I will say that as a Java developer I am grateful every day for the improvements to the language. Java is a very impressive language and I have a lot of respect for the people working on it.
评论 #37539122 未加载
评论 #37539159 未加载
评论 #37539215 未加载
评论 #37539481 未加载
评论 #37541394 未加载
评论 #37539210 未加载
评论 #37541425 未加载
slotrans超过 1 年前
&gt; This set of changes allows Java to express one of the foundations of functional programming that the language never could before - Algebraic data types, along with idiomatic ways of using them.<p>And here I thought the foundation of functional programming was <i>functions</i>, which Java still doesn&#x27;t have.<p>Seriously, functional programming is about functions, not types.
评论 #37541339 未加载
评论 #37542244 未加载
评论 #37542352 未加载
评论 #37541422 未加载
Horffupolde超过 1 年前
Can you convince me to use Java? I’ve never used it (only C++, Python, CL) but it feels bloated and dirty.
评论 #37539082 未加载
评论 #37539335 未加载
评论 #37539193 未加载
评论 #37539140 未加载
评论 #37541364 未加载
评论 #37539062 未加载
评论 #37539047 未加载
评论 #37539020 未加载
评论 #37539014 未加载
评论 #37541060 未加载
评论 #37539715 未加载
评论 #37541894 未加载
评论 #37541432 未加载
valenterry超过 1 年前
Finally Java catching up with some basic features that Scala has for 10 years or so. Hoping that more good stuff from Scala will get into Java soon, maybe at some point I can try to use Java again. :-)
评论 #37544409 未加载
xyst超过 1 年前
Big firms I have worked at still using Java 8.<p>Dead.
评论 #37539162 未加载
评论 #37539283 未加载
评论 #37539070 未加载
评论 #37539050 未加载
评论 #37541433 未加载
ArandomAccount2超过 1 年前
Has anyone used virtual threads? I tried to migrate my app over to VT&#x27;s and kept experiencing random deadlocks and I couldn&#x27;t figure out what was causing them. I tried moving all the synchronized blocks to reentrant locks, but that didn&#x27;t work. I also tried turning on the TV debugging system properties, but none of them printed the problem.
KillenBoek超过 1 年前
The problem with Java is not Java. It is Oracle and no amount of new features is going to fix that.
评论 #37539910 未加载
评论 #37539459 未加载
评论 #37539147 未加载
lakomen超过 1 年前
The biggest problem with Java is... the walled garden, the snob society, the elitist, exclusive culture.<p>Go isn&#x27;t like that, or at least wasn&#x27;t when G+ was still around.<p>Nowadays I don&#x27;t get in touch much with people, but when I create issues Go people are usually not as unfriendly as Java&#x2F;JVM people.
评论 #37544721 未加载
评论 #37544800 未加载
评论 #37544906 未加载
评论 #37544670 未加载