public class ConversionsPromotionsUtils extends Object
| 构造器和说明 |
|---|
ConversionsPromotionsUtils() |
| 限定符和类型 | 方法和说明 |
|---|---|
static boolean |
checkBoxingConversion(AClass s,
AClass t)
5.1.7 Boxing Conversion
Boxing conversion converts expressions of primitive type to corresponding
expressions of reference type.
|
static boolean |
checkIdentityConversion(AClass from,
AClass to)
5.1.1 Identity Conversion
A conversion from a type to that same type is permitted for any type.
|
static boolean |
checkMethodInvocatioConversion(AClass s,
AClass t) |
static boolean |
checkNarrowingPrimitiveConversion(AClass from,
AClass to)
5.1.3 Narrowing Primitive Conversion
22 specific conversions on primitive types are called the narrowing primitive conversions:
short to byte or char
char to byte or short
int to byte, short, or char
long to byte, short, char, or int
float to byte, short, char, int, or long
double to byte, short, char, int, long, or float
|
static boolean |
checkUnboxingConversion(AClass s,
AClass t)
5.1.8 Unboxing Conversion
Unboxing conversion converts expressions of reference type to corresponding
expressions of primitive type.
|
static boolean |
checkWideningAndNarrowingPrimitiveConversion(AClass from,
AClass to)
5.1.4 Widening and Narrowing Primitive Conversion
The following conversion combines both widening and narrowing primitive conversions:
byte to char
First, the byte is converted to an int via widening primitive conversion (§5.1.2),
and then the resulting int is converted to a char by narrowing primitive conversion (§5.1.3).
|
static boolean |
checkWideningPrimitiveConversion(AClass from,
AClass to)
5.1.2 Widening Primitive Conversion
19 specific conversions on primitive types are called the widening primitive conversions:
byte to short, int, long, float, or double
short to int, long, float, or double
char to int, long, float, or double
int to long, float, or double
long to float or double
float to double
|
static boolean |
checkWideningReferenceConversion(AClass s,
AClass t)
5.1.5 Widening Reference Conversion
A widening reference conversion exists from any reference type S to any reference
type T, provided S is a subtype (§4.10) of T.
|
public static boolean checkIdentityConversion(AClass from, AClass to)
A conversion from a type to that same type is permitted for any type.
This may seem trivial, but it has two practical consequences. First, it is always permitted for an expression to have the desired type to begin with, thus allowing the simply stated rule that every expression is subject to conversion, if only a trivial identity conversion. Second, it implies that it is permitted for a program to include redundant cast operators for the sake of clarity.
from - to - public static boolean checkWideningPrimitiveConversion(AClass from, AClass to)
byte to short, int, long, float, or doubleshort to int, long, float, or doublechar to int, long, float, or doubleint to long, float, or doublelong to float or doublefloat to doublefrom - to - public static boolean checkNarrowingPrimitiveConversion(AClass from, AClass to)
22 specific conversions on primitive types are called the narrowing primitive conversions:
from - to - public static boolean checkWideningAndNarrowingPrimitiveConversion(AClass from, AClass to)
The following conversion combines both widening and narrowing primitive conversions:
byte to char
First, the byte is converted to an int via widening primitive conversion (§5.1.2), and then the resulting int is converted to a char by narrowing primitive conversion (§5.1.3).
from - to - public static boolean checkWideningReferenceConversion(AClass s, AClass t)
5.1.5 Widening Reference Conversion
A widening reference conversion exists from any reference type S to any reference type T, provided S is a subtype (§4.10) of T.
Widening reference conversions never require a special action at run time and therefore never throw an exception at run time. They consist simply in regarding a reference as having some other type in a manner that can be proved correct at compile time.from - to - public static boolean checkBoxingConversion(AClass s, AClass t)
5.1.7 Boxing Conversion
Boxing conversion converts expressions of primitive type to corresponding expressions of reference type. Specifically, the following nine conversions are called the boxing conversions:
s - t - public static boolean checkUnboxingConversion(AClass s, AClass t)
Unboxing conversion converts expressions of reference type to corresponding expressions of primitive type. Specifically, the following eight conversions are called the unboxing conversions:
s - t - Copyright © 2015. All rights reserved.