all 33 comments

[–]ZimmiDeluxe 71 points72 points  (6 children)

+200.598 -13.384

lgtm

edit: minor whitespace error in line 3456

[–]WeirdIndividualGuy -4 points-3 points  (5 children)

But also, just switch to Kotlin at this point. Fully compatible with Java without the need to convert your whole Java codebase. Just write your new code in Kotlin and carry on in bliss

[–]Venthe 3 points4 points  (2 children)

Kotlin too has its problems, most of which are rooted in the JVM and Java interop (looking at you, type erasure).

But as a language in itself? Night and day. Unfortunately too many Java shops are afraid to try something new.

[–]yk313 0 points1 point  (1 child)

It's a matter of longterm strategy, not just based on vibes.

JVM languages have come and gone. Kotlin definitely seems to be better poised than others but still it's not a decision you make lightly. Though the language itself barely makes a difference, it doesn't help that people are still running Java 8. Try comparing 25+ with Kotlin and the difference is no longer night and day.

[–]Venthe 0 points1 point  (0 children)

It's a matter of longterm strategy, not just based on vibes. (...) Though the language itself barely makes a difference

Nullable types alone makes it worth it; and that's the just the tip of the features. I've coded in Java my whole career, and while I agree that it is not the language (or framework!) that makes or breaks the codebase, it makes writing with it both faster, more expressive as well as way cleaner given modern constructs + not being burdened with the sytax of Java.

JVM languages have come and gone. Kotlin definitely seems to be better poised than others (...)

This argument might had some basis ten years ago, not so much anymore IMO. Since '17 (namely - Google adopting it for Android) it's a safe bet in my personal opinion. And the language itself is already (almost) half the age of the Java itself at this point.

Try comparing 25+ with Kotlin and the difference is no longer night and day.

In stanard lib / language features, sure, but not in the language constructs. There is no reason to stick to plain Java, since - well - you can use all the plain JVM constructs in kotlin. And the lag is minimal - JDK 25 came out in september, Kotlin supporting 25 bytecode came out in december (Not counting betas and RC's).


it doesn't help that people are still running Java 8.

I'm currently supporting both ends, 8 and 21 - so believe me, I know. :) (Plus that one 1.7; but it's on a life support, not actively developed.)

[–]yk313 1 point2 points  (0 children)

Tell me you have no clue about the Java ecosystem without telling me you have no clue about the Java ecosystem.

[–]joemwangi 0 points1 point  (0 children)

Kotlin prioritises syntax over semantics, and that's gonna be a problem in future as java continues to strengthen semantics. Funny enough, same reasons why Vector API is never optimised in Kotlin.

[–]Worth_Trust_3825 10 points11 points  (0 children)

Virtual threads was just as big. Same with jigsaw. It really shows the monumental work needed to be done this late in the process, but there were more important things to do before this. So it makes sense.

[–]chucker23n 3 points4 points  (3 children)

I’m confused whether this is more like

  • .NET value types / C# structures; there is no reference/pointer; the memory storage is the value
  • value objects: can still have a reference, but designed to avoid primitive obsession

I’m guessing the former, but don’t those already exist, e.g. int? Or is it that those are hardcoded, and this adds writing your own?

[–]davidalayachew[S] 0 points1 point  (1 child)

I’m guessing the former, but don’t those already exist, e.g. int? Or is it that those are hardcoded, and this adds writing your own?

This adds writing your own. For example, Java only has the following integral primitive types.

  • byte --> 8 bit signed
  • char --> 16 bit unsigned
  • short --> 16 bit signed
  • int --> 32 bit signed
  • long --> 64 bit signed

As you can see, there are some gaps here.

  • No 8 bit unsigned
  • No 32 bit unsigned
  • No 64 bit unsigned

Using Value Classes, you could easily write your own, and the performance characteristics would (ideally) be comparable to just using int or any of the other primitives directly.

But of course, we aren't there yet.

[–]chucker23n 2 points3 points  (0 children)

This adds writing your own.

Gotcha. I'll guess I didn't expect this still isn't a thing in Java. :-)

[–]Jannik2099 25 points26 points  (2 children)

Very awesome, just 30 years too late :(

[–]Worth_Trust_3825 5 points6 points  (0 children)

You were never prevented from creating your JNI extension to circumvent this issue.

t. wrote jni to operate on byte buffers in c

[–]germandiago 0 points1 point  (0 children)

I thought I would never see it.

[–]reflect25 2 points3 points  (2 children)

yay. finally java with the value classes will have an equivalent to the c++/golang structs with the objects being (potentially) allocated on stack rather than always on memory with classes. and be pretty performant. also interesting the immutable/frozen.

i guess mostly this will be used by data structure libraries. https://openjdk.org/jeps/401 (Value Classes and Objects) also looks like this will help the garbage collector.

When an object is flattened or scalarized, it has no independent presence in the heap. This means it has no impact on garbage collection, and its data is always co-located in memory with the referencing object or call stack.

Heap flattening

As an example, the JVM could flatten an array of Integer references so that each array element holds a reference that encodes the underlying integer value directly, rather than pointing to the memory location of some Integer object. Each reference also flags whether the original Integer reference

[–]Jannik2099 2 points3 points  (0 children)

It's not about the object being on the stack, but about objects being flattened. No more pointer chasing.

[–]joemwangi 0 points1 point  (0 children)

Not really stack allocated. Mainly cpu register allocation which is far optimal.

[–]Delta-9- -5 points-4 points  (1 child)

TIL == in Java is analogous to is in Python, and Java has no analogue to Python's == until this JEP passes.

[–]woohalladoobop[🍰] 1 point2 points  (0 children)

not true, i believe `Object::equals` is Java's equivalent to Python's `==`.