Java Pulled Primitive Patterns After Five Previews. JDK 28 Won't Compile Them.
Primitive types in patterns, instanceof, and switch previewed in every JDK from 23 to 27. On November 9 the Amber team withdrew the feature, and it won't be in JDK 28 even with --enable-preview. Here's why Valhalla changed the plan, what replaces it, and how to rewrite code that used it.
Preview features in Java come with a warning label: they can change, or disappear. In practice, almost none disappear. A feature previews once or twice, gets polished, and goes final. That track record is why some teams quietly turn on --enable-preview and ship. This month the label turned out to mean what it says.
On November 9, Angelos Bimpoudis, the feature's JEP owner, told the amber-spec-experts list: "We have decided to cease development of Primitive Types in Patterns, instanceof, and switch." The feature previewed in JDK 23, 24, 25, 26 and 27. A sixth preview was drafted for JDK 28. Instead, the feature "will be removed in JDK 28 and will no longer be available in that release, even with --enable-preview."
Why Java Withdrew Primitive Patterns
The feature let switch and instanceof work with primitive types the way they already worked with objects. The key idea was "exact" conversion: value instanceof byte b matched only if the value fit in a byte without losing information.
The problem isn't the feature. It's what Project Valhalla is planning. From the announcement:
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.
In other words: if Java gets user-defined numeric types, say a Float16 or a Decimal written as a value class, "exact conversion" has to mean something for those too. Locking in a definition that only knows about int, long, double and friends could box the language in, and a final feature is very hard to change.
Withdrawing a preview is rare, but the process allows for it. The announcement points to JEP 12, which lets a preview be removed "through a JBS issue without requiring a new JEP."
| JDK | Status of primitive patterns |
|---|---|
| 23 | First preview, JEP 455 |
| 24 | Second preview, JEP 488 |
| 25 | Third preview, JEP 507 |
| 26 | Fourth preview, JEP 530, with a revised exactness definition and tighter dominance checks |
| 27 | Fifth preview, JEP 532, unchanged |
| 28 | Removed. A drafted sixth preview is withdrawn |
What the Feature Looked Like
Here's code I wrote using both parts of it:
// Primitive type patterns (preview in JDK 23-27, removed in JDK 28).
public class Status {
static String describe(int code) {
return switch (code) {
case 0 -> "okay";
case 1 -> "warning";
case int i when i >= 500 -> "server error " + i;
case int i -> "unknown status " + i;
};
}
static String fitsInByte(int value) {
// Matches only if the int converts to byte without losing information.
if (value instanceof byte b) {
return value + " fits in a byte: " + b;
}
return value + " does not fit in a byte";
}
public static void main(String[] args) {
System.out.println(describe(1));
System.out.println(describe(503));
System.out.println(describe(42));
System.out.println(fitsInByte(100));
System.out.println(fitsInByte(300));
}
}
On JDK 27.0.1 without the preview flag, javac refuses:
Status.java:7: error: primitive patterns are a preview feature and are disabled by default.
case int i when i >= 500 -> "server error " + i;
^
(use --enable-preview to enable primitive patterns)
With javac --release 27 --enable-preview and java --enable-preview, it runs:
warning
server error 503
unknown status 42
100 fits in a byte: 100
300 does not fit in a byte
The case int i patterns and instanceof byte are exactly what goes away. On JDK 28 that file won't compile at all.
We recommend reading JDK 27 New Features Explained: What Actually Changes to continue reading our selection of content. Primitive patterns were one of JDK 27's preview features, and that piece covers what else in 27 is final and what's still preview.
JDK 27 New Features Explained: What Actually Changes JDK 27 ships nine JEPs, but only a few actually change your code today. What's default now, what's still preview, and what to do about each one now. SudoSecurity · lagoon
Even Compiled Code Won't Carry Over
You might hope that code compiled with JDK 27 would keep running. It won't, and that has nothing to do with this withdrawal. JEP 12 says a class file that depends on preview features is marked "by having a major_version item that corresponds to Java SE $N and a minor_version item that has all 16 bits set." Only the JVM for that exact release loads it, and only with --enable-preview.
The class file I compiled on JDK 27 reports exactly that:
major 71 minor 0xffff
Version 71 is Java 27. JDK 28's JVM won't load it. Anything built with preview features has to be recompiled for every release anyway, so the withdrawal hits you at compile time, not at runtime.
How to Rewrite It
Nothing here needs a library or a new API. The same logic, written for any JDK:
// The same logic without primitive patterns, for JDK 28.
public class StatusPlain {
static String describe(int code) {
return switch (code) {
case 0 -> "okay";
case 1 -> "warning";
default -> code >= 500 ? "server error " + code : "unknown status " + code;
};
}
static String fitsInByte(int value) {
if (value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE) {
byte b = (byte) value;
return value + " fits in a byte: " + b;
}
return value + " does not fit in a byte";
}
public static void main(String[] args) {
System.out.println(describe(1));
System.out.println(describe(503));
System.out.println(describe(42));
System.out.println(fitsInByte(100));
System.out.println(fitsInByte(300));
}
}
It compiled without any flags on JDK 27 and printed the same five lines. Two things are lost:
- The guard on a primitive.
case int i when i >= 500becomes adefaultbranch with anifor a ternary inside it. - The exactness check.
instanceof byte bdid the range check for you. For integer types, a hand-written range check like the one above is all you need. Floating point is harder.
The double to long trap
The obvious replacement for d instanceof long l is a round trip: cast to long, cast back, and compare. I ran both on JDK 27 with the preview on, using d instanceof long l and (double) (long) d == d:
| Input | Preview pattern | Round trip |
|---|---|---|
42.0 |
match | match |
42.5 |
no match | no match |
-0.0 |
no match | match |
NaN |
no match | no match |
0x1p63 (2^63) |
no match | match |
-0x1p63 (-2^63) |
match | match |
The round trip gets two cases wrong. -0.0 casts to 0 and back to 0.0, which compares equal to -0.0. And 2^63 is one past Long.MAX_VALUE, but the cast saturates to Long.MAX_VALUE, which rounds back to 2^63 as a double. If the check guards a database ID or an array index, that's a silent wrong answer.
This version matched the preview on all six inputs:
// An exact double-to-long check that doesn't need preview features.
public class ExactLong {
static boolean fitsInLong(double d) {
return d >= -0x1p63 && d < 0x1p63 // in range; NaN fails both
&& d == Math.floor(d) // no fractional part
&& Double.doubleToRawLongBits(d) != Double.doubleToRawLongBits(-0.0); // not -0.0
}
public static void main(String[] args) {
double[] inputs = { 42.0, 42.5, -0.0, Double.NaN, 0x1p63, -0x1p63 };
for (double d : inputs) {
System.out.printf("%-24s fitsInLong=%b%n", d, fitsInLong(d));
}
}
}
42.0 fitsInLong=true
42.5 fitsInLong=false
-0.0 fitsInLong=false
NaN fitsInLong=false
9.223372036854776E18 fitsInLong=false
-9.223372036854776E18 fitsInLong=true
Whether you want -0.0 rejected depends on your code. The preview rejected it, so this does too.
To find code that needs changing, compile with JDK 27 and -Xlint:preview, or build against a JDK 28 early-access release once the removal lands there. Every case int, case long, case double, and instanceof with a primitive type will fail.
We recommend reading Twelve Years in the Making: JDK 28 Ships Value Classes Preview to continue reading our selection of content. Valhalla's value classes are the reason this feature was pulled, and that piece covers what they are and where they stand in JDK 28.
Twelve Years in the Making: JDK 28 Ships Value Classes Preview JDK 28 previews value classes after twelve years of Project Valhalla work. What's in the March 2027 feature release and what it means for Java developers. SudoSecurity · Santhdium
What Replaces It
Not all of it is lost. The announcement says a different feature, Constant Patterns, "already carries forward work from Primitive Patterns, including expanded primitive support in switch expressions and statements." It lets constants appear as patterns nested inside record patterns, such as case Point(0, 0), instead of needing a when clause. A draft JEP for it is due "shortly."
That's narrower. Constant patterns match specific values. They don't bind a primitive to a variable with an exactness check. Whether exact conversion returns later depends on where Valhalla's numeric work lands.
What This Doesn't Cover
I ran the examples on JDK 27.0.1 from the eclipse-temurin:27-jdk image and checked class file versions with JDK 25. I didn't have a JDK 28 build containing the removal, so the JDK 28 behavior is from the announcement, not a test. The Constant Patterns JEP wasn't published when I wrote this, so I can't show its syntax beyond the case Point(0, 0) example.
For the wider history of where Java's previews have been heading, our Java 26 overview covers the release where this feature got its last real change.
The Actual Point
--enable-preview means what it says. A feature that previewed five times in a row, with a sixth already drafted, is gone from the next release because a bigger design might need it to work differently.
If you used primitive patterns, rewrite them as default branches and explicit range checks before you move to JDK 28. If you ship anything with --enable-preview, treat this as the reminder of what you signed up for.
Quotes are from the November 9, 2026 message to amber-spec-experts, signed by Angelos Bimpoudis and Gavin, JEP 532, and JEP 12. The Java programs, including the two-way comparison behind the table, are original code using only the language and java.lang, compiled and run on November 16, 2026 with OpenJDK 27.0.1 in the eclipse-temurin:27-jdk image, and the compiler error and outputs are reproduced from those runs. The class file version was read from the compiled Status.class.
$ tail -f /forums
Discussion
Comments live on the community forums — sign in there to reply.