Its about widening. I always think if i am right or wrong. As far as i understood, Widening of primitive datatypes means, moving upwards.i.e byte-> short-> int-> long->float->double.
Widening at objects level means,
Hope i am right, if not, correct me
[ December 16, 2008: Message edited by: James Tharakan ] [ December 17, 2008: Message edited by: James Tharakan ]
SCJP 6
Why to worry about things in which we dont have control, Why to worry about things in which we have control ! !
Yes, you are right James except when you say int->Integer->Number->Object, for example. In the above case, int is boxed to Integer first and then widening is applied.
In general widening means going to class/interface which is more general, on contrary narrowing means moving to more specific classes.
When it's obvious that you have to do it, just do it without shattering your thoughts over different directions.
If primitive type int is converted to wrapper Integer, it is called boxing.
int----> Integer is boxing. Integer---> int is unboxing.
Now boxing and unboxing are done by compiler, so it is called autoboxing and autounboxing.
If Integer is converted to Number, it is called upcasting or implicit casting, as it happens implicitly. If Number is converted to Integer, it is called downcasting or explicit casting, as we have to do it explicitly. like: Number n; Integer i=(Integer)n;
@punit When you say 'autounboxing', you are wrong. It's 'unboxing' basically. And I think the usage of word 'widening' in case of object level is also meaningful. [ December 17, 2008: Message edited by: Rajshekhar Paul ]
When it's obvious that you have to do it, just do it without shattering your thoughts over different directions.