Live data from Hacker News

Java 20 / JDK 20: General Availability

mail.openjdk.org

211–220 of 356 posts

Re: Java 20 / JDK 20: General Availability

#212
post #177
post #174

What are some good primers to understand the prominent new Java features? Not just in 20, but since, say, 8. Asking as someone who would like to be cursorily familiar with Java, but does not use it day to day. I'm very familiar with things like auto type inference, pattern matching, multi-line strings and structured concurrency from other languages, so I'm not looking for an introduction to Java. I'm looking for some…

Boring answer... but Chat GPT? I asked it what was new in Java 8 and it enumerated a number of features. I could proceed to ask it about more details for each, and then continue Java version by version and I think it would be quite exhaustive. The other day I did something similar for cell biology. As a layman I wanted to learn more about DNA, mRNA, tRNA, translation, transcription, mitosis, miosis, etc. I think I le…

I've avoided that because of the tedium of having to fact check everything.

Re: Java 20 / JDK 20: General Availability

#213

its amazing how much the world hasn’t been able to keep up with java. github PRs still have no syntax highlighting support for record and var

With Java it's always win/win. If external software works with it, "Java has great tooling", if it doesn't, the rest of the world is slow.

Re: Java 20 / JDK 20: General Availability

#214
post #147

Earlier quoted context omitted.

Because it is an expression that introduces a new keyword. You could say “return match…” It’s not easy to introduce without breakage. Not saying it cannot be done. But PHP didn’t manage to for example. It also isn’t real pattern matching but that’s a different issue.

Oh, so you were referring to the specific syntax in the current proposal, rather than pattern matching in general? Java and C# show how the syntax can be done in a fully backwards-compatible manner. It looks like it's just not the JS way by choice - apparently every new keyword that was added since ES5 is an actual keyword reserved in all contexts, not context-dependent?

That’s good to hear!

Re: Java 20 / JDK 20: General Availability

#215
Coming from the telegram bot of hacker news, where this post has a lot of downvotes (21 down to 6 up, which is quite a lot for how many reactions usually are there), could someone (perhaps even from people who downvoted) explain why this news is met with such negativity?

I kind of assume it's due to the cliché Java-oriented hatred, but curious to hear opinions...

Re: Java 20 / JDK 20: General Availability

#216

Earlier quoted context omitted.

I haven't looked into CLR in a long time, but it feels like it has a fraction of JVM's adoption and community size. Microsoft also seems to be prioritizing Typescript and Node internally with its recent moves.

At the risk of starting a flame war, the CLI and the coreCLR are fare superior VM and platform from a technical stand point. A lot of the features schedule for jave 21 / project Valhalla are just basically catching up to modern VM design. Of course there is more to the choice of a platform than just the technical differences.

Im what aspect is the VM “far superior”? Where are CLR’s state-of-the-art GC or low-level GC? Or does it have observability tools like JFR?

Re: Java 20 / JDK 20: General Availability

#217

Minor typo in the linked site: "JDK 20 reached General Availability on 21 March 2022" Should be 21 March 2023 Not sure who can edit that page but putting here.

Just adding too, I think some of the switch statement example code is wrong: Object obj = 123L; String formatted = switch (obj) { case Integer i -> String.format("int %d", i); case Long l -> String.format("long %d", l); case Double d -> String.format("double %f", d); case String s -> String.format("String %s", s); default -> o.toString(); }; Unless I'm not understanding something, the default statement should be `obj…

JFC, I was going to say they should have used `String.valueOf(obj)` since I expected `Object obj = null; switch (obj) { default ->` to do something sane but no, the stupid PoS NPEs because `switch` itself evidently calls `Objects.requireNonNull`

The Billion Dollar Mistake meets the Power of Compounding Interest to produce an inflation adjusted number that just keeps on giving

Re: Java 20 / JDK 20: General Availability

#218
post #166

Earlier quoted context omitted.

I unfortunately encounter this mindset so much in Java programmers, and the similar "we don't need no feature X" even if the feature has proven themselves for a long time in a large amount of languages. I'm hesitant to bring it up, but I see a lot of Blub Paradox [1] among Java programmers. Heck, a lot of places disallow `var`, while over here in Kotlin-Python-Rust-C#-Typescript-Go-etc-land that's been the default si…

Var is nice. But I generally prefer to not require people to jump out of the current code to figure out the type of a variable. And yeah, I've worked in those other languages, and navigating unfamiliar code with var everywhere can be confusing, so I try to avoid that kinda thing. Records are nearly useless to me. Immutability is great, but I need a way to derive new sets of information based upon an set of informatio…

`var` in Java is local for a reason. In most contexts I can think of the variable either was created above or was passed in as a parameter/object field. Unless you set it from a weirdly named creation pattern/function.

Regarding records, you never had someone update a POJO, add a field, and forget to update equals and hashCode?

Sealed classes are great for everything parsing/validation, in data modelling. They're not a solution for behavior polimorphism, but I don't think they were supposed to.

Re: Java 20 / JDK 20: General Availability

#220

Earlier quoted context omitted.

What’ the hype with pattern matching? What does it solve?

It's really nice syntactic sugar. Complicated conditional logic cluttered with redundant types turns into a series of simple patterns. "Just" makes it easier to not make stupid bugs (I'm all for it).

Agreed. Example from Scala

  // Given an Option
  val maybeThing: Option[String] = getThing()  

  // Classic
  if (maybeThing.isDefined) {
    useThing(maybeThing.get)
  } else {
    NotFoundResponseEtc()
  }  

  // Pattern matching (not too IDE auto generated exhaustive match cases!)
  maybeThing match {
    case Some(thing) => useThing(thing)
    case None        => NotFoundResponseEtc()
  }

This scales well when matching a higher cardinality of things like a variety of Exceptions or enums or other tuple responses like Either etc.
Post reply on HN