CONVERSIONS AND PROMOTIONS(3)
CONVERSIONS AND PROMOTIONS(3)
(Kinds of conversions):
7. BOXING CONVERSIONS: boxing conversions converts values of positive types to corresponding values of reference types.
- from type boolean to type Boolean
- from type byte to type Byte
- from type char to type Character
- from type short to type Short
- from type int to type Integer
- from type long to type Long
- from type float to type Float
- from type double to type Double
public class Loader {
public static void main(String[] args) {
//boxing from boolean to Boolean!
boolean p = true;
Boolean p2 = p;
System.out.print("According to the jls, ps is: ");
System.out.println(p2.booleanValue());
}
}
8. UNBOXING CONVERSIONS: this is BOXING CONVERSIONS the other way round. Note that a type is said to be convertible to a numeric type if it is a numeric type, or it is a reference type that may be converted to a numeric type by unboxing conversions. A type is said to be convertible to an integral type if it is an integral type, or it is a reference type that may be converted to an integral type by unboxing conversion.
9. UNCHECKED CONVERSION: if G is a parameterized type with n type parameters. There is an unchecked conversion from the raw type G to any parameterized type of the form G
public class Loader {
public static void main(String[] args) {
S pss = new S();
S
}
}
10. CAPTURE CONVERSION: (sorry, my compiler does not allow wildcard parameters so at a loss on how to express this section. Will look for a way around this though.)
11. STRING CONVERSIONS: a string conversion to type String from every other type exists, including the null type.
12. FORBIDDEN CONVERSIONS: any non-explicitly allowed conversion is forbidden.
13. VALUE SET CONVERSION: value set conversion is the process of mapping a floating-point value from one value set to another without changing its type. Value set conversion occurs within expressions that are either or not FP-strict[1].
If an expression is FP-strict, the value set conversion must be within the float or double value set, to the nearest element, and may result in underflow or overflow.
If an expression is not FP-strict, the java programming language has optional value set conversion choices for implementation of the expression.
1. if the value is within the the float-extended-exponent value set, the implementation may optionally be to the nearest element of the float value set.
2. if the element is of the double-extended-exponent value set, then the implementation may optionally map the value to the nearest element of the double value set.
[1]. FP-strict expressions: these are expressions that are either 1, compile-time constant expressions , or b, if not the above then they must bear a strictfp modifier in its declaration. All FP-strict expressions provide intermediate values that lie within the floating-point value set.

No comments:
Post a Comment