What is the difference between these two. I know Boxing is converting primitive values to reference. What is widening. Also what should be the sequence first boxing should be done or widening should be done?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
Widening is when assign
byte
toint
. i.e. you are widening the data type.Sequence must be
boxing
thenwidening
.Note: Highlighted words are from Sun Certified Java Programmer SCJP 6 - Kathy Sierra
Widening is transforming a variable in another with a wider type.
Widening can be done with primitive or reference types.
For example :
String
->Object
int
->long
As the JLS states :
Resources :
Widening is transforming a primitive or non primitive to a wider type (i.e. one that can hold more bytes).
Example:
But,
int -> Integer
is not widening; it's boxing. Widening has a higher priority than boxing. Also both widening and boxing can't be done together, i.e.I think the order is pretty fascinating. I made out the following playground to see every possible combination. This are my functions:
Rules: