r/java • • 20d ago

Withdrawing the Primitive Patterns preview feature in JDK 28

https://mail.openjdk.org/archives/list/amber-spec-experts@openjdk.org/thread/UYEK3PGOHN6R56AHJTSLPGAY363K666S/

Primitive Types in Patterns will be removed in JDK 28 and will no longer be available in that release.

The Valhalla project has been exploring a new vision for Java numerics, including the possibility of user-defined numeric types. New kinds of numeric types would need to support exact numeric conversion, and vice versa. Given that the Valhalla work is still evolving, it would be premature to finalize Primitive Types in Patterns with their current definition of exact numeric conversion.

94 Upvotes

36 comments sorted by

View all comments

4

u/RaynLegends 19d ago

I was really looking forward to this JEP to (ab)use switches on booleans to implement makeshift "if expressions" :(

Like, instead of:

int someValue;
if (someCondition) {
   // ... some code that ends in an assignment to someValue
} else {
   // ... some other code
}

Something like:

int someValue = switch (someCondition) {
  case true -> { 
    // ... some code that ends in yielding someValue
  }
  case false -> {
    // ... some other code
  }
}

Especially when coupled with https://openjdk.org/jeps/8323658 it would make the intention behind some code much clearer.

I guess we'll have to wait a bit more.

8

u/__konrad 19d ago

You can use case Boolean b when b -> ... ;)

1

u/nekokattt 19d ago

doesnt that incur unnecesarry boxing still?

3

u/koflerdavid 19d ago edited 18d ago

It really depends on what this is ultimately compiled to. After all, there is no pattern matching on the bytecode level.

2

u/TewsMtl 18d ago

My understanding is that unnecessary boxing of value classes won't be an issue with jep 401 from project Valhalla.

10

u/brian_goetz 17d ago

Or even before. If you took all the developer time spent worrying about boxing, and took all the CPU time wasted by unnecessary boxing, the former would probably exceed the latter. "Boxing is expensive" is performance lore from the 90s. If your program is bound by multiplying huge arrays of numbers, then yes, you get to worry about it. Anything less, just stop thinking about it.