Get the latest tech news

JEP-455: Primitive types in patterns, instanceof and switch


Types in Patterns, instanceof, and switch (Preview) Summary Enhance pattern matching by allowing primitive type patterns in all pattern contexts, and extend instanceof and switch to work with all primitive types. This is a preview language feature.

Primitive type patterns in instanceof would subsume the lossy conversions built into the Java language and avoid the painstaking range checks that developers have been coding by hand for almost three decades. Instead of throwing an exception, it can silently lose information such as magnitude, sign, or precision, allowing the improperly cast value to flow into the rest of the program. Now that primitive type patterns can be used widely, matching is generalized to mean that a value can be cast exactly to T, which covers throwing a ClassCastException as well as potential loss of information.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of patterns

patterns

Photo of Primitive types

Primitive types

Photo of JEP-455

JEP-455

Related news:

News photo

Patterns (YC S21), hiring to build a universal finance and accounting data model

News photo

New acoustic attack determines keystrokes from typing patterns

News photo

Patterns And Issues In AI Chip Design