APIdia Launch Partner
Top Description Constructors Methods
java.lang.runtime

public final Class ExactConversionsSupport

extends Object
Class Inheritance

A testing conversion of a value is exact if it yields a result without loss of information or throwing an exception. Otherwise, it is inexact. Some conversions are always exact regardless of the value. These conversions are said to be unconditionally exact.

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:

Implementation Note

Some exactness checks describe a test which can be redirected safely through one of the existing methods. Those are omitted too (i.e., byte to char can be redirected to ExactConversionsSupport#isIntToCharExact(int), short to byte can be redirected to ExactConversionsSupport#isIntToByteExact(int) and similarly for short to char, char to byte and char to short to the corresponding methods that take an int).

Since
23
Java Language Specification
primitive-types-in-patterns-instanceof-switch-5.7.1 Exact Testing Conversions, primitive-types-in-patterns-instanceof-switch-5.7.2 Unconditionally Exact Testing Conversions, primitive-types-in-patterns-instanceof-switch-15.20.2 The instanceof Operator

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static boolean

Returns:

true if and only if the passed value can be converted exactly to the target type
isDoubleToByteExact
(double
value
n
)

Exactness method from double to byte

public static boolean

Returns:

true if and only if the passed value can be converted exactly to the target type
isDoubleToCharExact
(double
value
n
)

Exactness method from double to char

public static boolean

Returns:

true if and only if the passed value can be converted exactly to the target type
isDoubleToFloatExact
(double
value
n
)

Exactness method from double to float

public static boolean

Returns:

true if and only if the passed value can be converted exactly to the target type
isDoubleToIntExact
(double
value
n
)

Exactness method from double to int

public static boolean

Returns:

true if and only if the passed value can be converted exactly to the target type
isDoubleToLongExact
(double
value
n
)

Exactness method from double to long

public static boolean

Returns:

true if and only if the passed value can be converted exactly to the target type
isDoubleToShortExact
(double
value
n
)

Exactness method from double to short

public static boolean

Returns:

true if and only if the passed value can be converted exactly to the target type
isFloatToByteExact
(float
value
n
)

Exactness method from float to byte

public static boolean

Returns:

true if and only if the passed value can be converted exactly to the target type
isFloatToCharExact
(float
value
n
)

Exactness method from float to char

public static boolean

Returns:

true if and only if the passed value can be converted exactly to the target type
isFloatToIntExact
(float
value
n
)

Exactness method from float to int

public static boolean

Returns:

true if and only if the passed value can be converted exactly to the target type
isFloatToLongExact
(float
value
n
)

Exactness method from float to long

public static boolean

Returns:

true if and only if the passed value can be converted exactly to the target type
isFloatToShortExact
(float
value
n
)

Exactness method from float to short

public static boolean

Returns:

true if and only if the passed value can be converted exactly to the target type
isIntToByteExact
(int
value
n
)

Exactness method from int to byte

public static boolean

Returns:

true if and only if the passed value can be converted exactly to the target type
isIntToCharExact
(int
value
n
)

Exactness method from int to char

public static boolean

Returns:

true if and only if the passed value can be converted exactly to the target type
isIntToFloatExact
(int
value
n
)

Exactness method from int to float

public static boolean

Returns:

true if and only if the passed value can be converted exactly to the target type
isIntToShortExact
(int
value
n
)

Exactness method from int to short

public static boolean

Returns:

true if and only if the passed value can be converted exactly to the target type
isLongToByteExact
(long
value
n
)

Exactness method from long to byte

public static boolean

Returns:

true if and only if the passed value can be converted exactly to the target type
isLongToCharExact
(long
value
n
)

Exactness method from long to char

public static boolean

Returns:

true if and only if the passed value can be converted exactly to the target type
isLongToDoubleExact
(long
value
n
)

Exactness method from long to double

public static boolean

Returns:

true if and only if the passed value can be converted exactly to the target type
isLongToFloatExact
(long
value
n
)

Exactness method from long to float

public static boolean

Returns:

true if and only if the passed value can be converted exactly to the target type
isLongToIntExact
(long
value
n
)

Exactness method from long to int

public static boolean

Returns:

true if and only if the passed value can be converted exactly to the target type
isLongToShortExact
(long
value
n
)

Exactness method from long to short

private static boolean
isNegativeZero(float n)

private static boolean
isNegativeZero(double n)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

ExactConversionsSupportback to summary
private ExactConversionsSupport()

Method Detail

isDoubleToByteExactback to summary
public static boolean isDoubleToByteExact(double n)

Exactness method from double to byte

Implementation Specification

relies on the notion of representation equivalence defined in the specification of the Double class.

Parameters
n:double

value

Returns:boolean

true if and only if the passed value can be converted exactly to the target type

isDoubleToCharExactback to summary
public static boolean isDoubleToCharExact(double n)

Exactness method from double to char

Implementation Specification

relies on the notion of representation equivalence defined in the specification of the Double class.

Parameters
n:double

value

Returns:boolean

true if and only if the passed value can be converted exactly to the target type

isDoubleToFloatExactback to summary
public static boolean isDoubleToFloatExact(double n)

Exactness method from double to float

Implementation Specification

relies on the notion of representation equivalence defined in the specification of the Double class.

Parameters
n:double

value

Returns:boolean

true if and only if the passed value can be converted exactly to the target type

isDoubleToIntExactback to summary
public static boolean isDoubleToIntExact(double n)

Exactness method from double to int

Implementation Specification

relies on the notion of representation equivalence defined in the specification of the Double class.

Parameters
n:double

value

Returns:boolean

true if and only if the passed value can be converted exactly to the target type

isDoubleToLongExactback to summary
public static boolean isDoubleToLongExact(double n)

Exactness method from double to long

Implementation Specification

relies on the notion of representation equivalence defined in the specification of the Double class.

Parameters
n:double

value

Returns:boolean

true if and only if the passed value can be converted exactly to the target type

isDoubleToShortExactback to summary
public static boolean isDoubleToShortExact(double n)

Exactness method from double to short

Implementation Specification

relies on the notion of representation equivalence defined in the specification of the Double class.

Parameters
n:double

value

Returns:boolean

true if and only if the passed value can be converted exactly to the target type

isFloatToByteExactback to summary
public static boolean isFloatToByteExact(float n)

Exactness method from float to byte

Implementation Specification

relies on the notion of representation equivalence defined in the specification of the Double class.

Parameters
n:float

value

Returns:boolean

true if and only if the passed value can be converted exactly to the target type

isFloatToCharExactback to summary
public static boolean isFloatToCharExact(float n)

Exactness method from float to char

Implementation Specification

relies on the notion of representation equivalence defined in the specification of the Double class.

Parameters
n:float

value

Returns:boolean

true if and only if the passed value can be converted exactly to the target type

isFloatToIntExactback to summary
public static boolean isFloatToIntExact(float n)

Exactness method from float to int

Implementation Specification

relies on the notion of representation equivalence defined in the specification of the Double class.

Parameters
n:float

value

Returns:boolean

true if and only if the passed value can be converted exactly to the target type

isFloatToLongExactback to summary
public static boolean isFloatToLongExact(float n)

Exactness method from float to long

Implementation Specification

relies on the notion of representation equivalence defined in the specification of the Double class.

Parameters
n:float

value

Returns:boolean

true if and only if the passed value can be converted exactly to the target type

isFloatToShortExactback to summary
public static boolean isFloatToShortExact(float n)

Exactness method from float to short

Implementation Specification

relies on the notion of representation equivalence defined in the specification of the Double class.

Parameters
n:float

value

Returns:boolean

true if and only if the passed value can be converted exactly to the target type

isIntToByteExactback to summary
public static boolean isIntToByteExact(int n)

Exactness method from int to byte

Parameters
n:int

value

Returns:boolean

true if and only if the passed value can be converted exactly to the target type

isIntToCharExactback to summary
public static boolean isIntToCharExact(int n)

Exactness method from int to char

Parameters
n:int

value

Returns:boolean

true if and only if the passed value can be converted exactly to the target type

isIntToFloatExactback to summary
public static boolean isIntToFloatExact(int n)

Exactness method from int to float

Implementation Specification

relies on the notion of representation equivalence defined in the specification of the Double class.

Parameters
n:int

value

Returns:boolean

true if and only if the passed value can be converted exactly to the target type

isIntToShortExactback to summary
public static boolean isIntToShortExact(int n)

Exactness method from int to short

Parameters
n:int

value

Returns:boolean

true if and only if the passed value can be converted exactly to the target type

isLongToByteExactback to summary
public static boolean isLongToByteExact(long n)

Exactness method from long to byte

Parameters
n:long

value

Returns:boolean

true if and only if the passed value can be converted exactly to the target type

isLongToCharExactback to summary
public static boolean isLongToCharExact(long n)

Exactness method from long to char

Parameters
n:long

value

Returns:boolean

true if and only if the passed value can be converted exactly to the target type

isLongToDoubleExactback to summary
public static boolean isLongToDoubleExact(long n)

Exactness method from long to double

Implementation Specification

relies on the notion of representation equivalence defined in the specification of the Double class.

Parameters
n:long

value

Returns:boolean

true if and only if the passed value can be converted exactly to the target type

isLongToFloatExactback to summary
public static boolean isLongToFloatExact(long n)

Exactness method from long to float

Implementation Specification

relies on the notion of representation equivalence defined in the specification of the Double class.

Parameters
n:long

value

Returns:boolean

true if and only if the passed value can be converted exactly to the target type

isLongToIntExactback to summary
public static boolean isLongToIntExact(long n)

Exactness method from long to int

Parameters
n:long

value

Returns:boolean

true if and only if the passed value can be converted exactly to the target type

isLongToShortExactback to summary
public static boolean isLongToShortExact(long n)

Exactness method from long to short

Parameters
n:long

value

Returns:boolean

true if and only if the passed value can be converted exactly to the target type

isNegativeZeroback to summary
private static boolean isNegativeZero(float n)
isNegativeZeroback to summary
private static boolean isNegativeZero(double n)