public final class ExactConversionsSupport extends Object
For example, a conversion from int to byte for the value 10 is exact because the result, 10, is the same as the original value. In contrast, if the int variable i stores the value 1000 then a narrowing primitive conversion to byte will yield the result -24. Loss of information has occurred: both the magnitude and the sign of the result are different than those of the original value. As such, a conversion from int to byte for the value 1000 is inexact. Finally a widening primitive conversion from byte to int is unconditionally exact because it will always succeed with no loss of information about the magnitude of the numeric value.
The methods in this class provide the run-time support for the exactness checks of testing conversions from a primitive type to primitive type. These methods may be used, for example, by Java compiler implementations to implement checks for instanceof and pattern matching runtime implementations. Unconditionally exact testing conversions do not require a corresponding action at run time and, for this reason, methods corresponding to these exactness checks are omitted here.
The run time conversion checks examine whether loss of information would occur if a testing conversion would be to be applied. In those cases where a floating-point primitive type is involved, and the value of the testing conversion is either signed zero, signed infinity or NaN, these methods comply with the following:
NaN or infinity to an integer type is considered inexact.NaN or infinity or signed zero to another floating-point type is considered exact.byte to char can be redirected to isIntToCharExact(int), short to byte can be redirected to isIntToByteExact(int) and similarly for short to char, char to byte and char to short to the corresponding methods that take an int).| Modifier and Type | Method | Description |
|---|---|---|
static boolean |
isDoubleToByteExact |
Exactness method from double to byte |
static boolean |
isDoubleToCharExact |
Exactness method from double to char |
static boolean |
isDoubleToFloatExact |
Exactness method from double to float |
static boolean |
isDoubleToIntExact |
Exactness method from double to int |
static boolean |
isDoubleToLongExact |
Exactness method from double to long |
static boolean |
isDoubleToShortExact |
Exactness method from double to short |
static boolean |
isFloatToByteExact |
Exactness method from float to byte |
static boolean |
isFloatToCharExact |
Exactness method from float to char |
static boolean |
isFloatToIntExact |
Exactness method from float to int |
static boolean |
isFloatToLongExact |
Exactness method from float to long |
static boolean |
isFloatToShortExact |
Exactness method from float to short |
static boolean |
isIntToByteExact |
Exactness method from int to byte |
static boolean |
isIntToCharExact |
Exactness method from int to char |
static boolean |
isIntToFloatExact |
Exactness method from int to float |
static boolean |
isIntToShortExact |
Exactness method from int to short |
static boolean |
isLongToByteExact |
Exactness method from long to byte |
static boolean |
isLongToCharExact |
Exactness method from long to char |
static boolean |
isLongToDoubleExact |
Exactness method from long to double |
static boolean |
isLongToFloatExact |
Exactness method from long to float |
static boolean |
isLongToIntExact |
Exactness method from long to int |
static boolean |
isLongToShortExact |
Exactness method from long to short |
public static boolean isIntToByteExact(int n)
n - valuepublic static boolean isIntToShortExact(int n)
n - valuepublic static boolean isIntToCharExact(int n)
n - valuepublic static boolean isIntToFloatExact(int n)
n - valuepublic static boolean isLongToByteExact(long n)
n - valuepublic static boolean isLongToShortExact(long n)
n - valuepublic static boolean isLongToCharExact(long n)
n - valuepublic static boolean isLongToIntExact(long n)
n - valuepublic static boolean isLongToFloatExact(long n)
n - valuepublic static boolean isLongToDoubleExact(long n)
n - valuepublic static boolean isFloatToByteExact(float n)
n - valuepublic static boolean isFloatToShortExact(float n)
n - valuepublic static boolean isFloatToCharExact(float n)
n - valuepublic static boolean isFloatToIntExact(float n)
n - valuepublic static boolean isFloatToLongExact(float n)
n - valuepublic static boolean isDoubleToByteExact(double n)
n - valuepublic static boolean isDoubleToShortExact(double n)
n - valuepublic static boolean isDoubleToCharExact(double n)
n - valuepublic static boolean isDoubleToIntExact(double n)
n - valuepublic static boolean isDoubleToLongExact(double n)
n - valuepublic static boolean isDoubleToFloatExact(double n)
n - value
© 1993, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/runtime/ExactConversionsSupport.html