Originally posted by Burkhard Hassel: You cannot first box and then widen!
But the other way round, it works:Integer i=(int) s.charAt(2);
here, the char is first widened to an int primi. This int primi then can be boxed to an Integer.
Deepthi Kanakam Rajan
Joined: May 15, 2006
Originally posted by Deepthi Kanakam Rajan: [QB][/QB]
sorry forgot to add my query to that which is according to K&B book its mentioned that:
One can box and then widen and not the other way while your statement contradicts it.
Can you please clarify this as I am confused now
Shivaprasad P Kanaganahallimath
Joined: Sep 25, 2006
thank you all I got it!!
Joined: Aug 25, 2006
One can box and then widen
this is wrong.
you cannot first box and then widen:
or: int i = 54321; Long lo = i; // no compile
or verbose: int i = 5; Integer inti = i; // ok so far but Long lo = inti; // no way!
But you can first widen and then box.
Here no two-liner is possible.
K&B book says somewhere "an int can never become a Long", or something like that. But this is not correct in general. It's only correct, if you try it in the short cut coding style like in my example with the 54321.