Java 5 introduced the concept of autoboxing which is helpful in some cases. However, if you try to do the following it won't work
Float f = 5;
Does any one know why? In the primitive counterpart example float f = 5; is legally perfect while the autoboxing version is not!!!
Is it a bug or what?
[ February 08, 2006: Message edited by: Craig Tyler ]
Originally posted by Craig Tyler:
Remember, you can Box then Widen, but you can't Widen then Box. Beforehand, if you did float f = 5, the integer would be implicitly widened into a float, but since you can't implicitly widen the int to a float before boxing it as a Float, this doesn't work.
How does this work then ?
Yeah, I got an 'incompatibe types' error while compiling from command prompt.
But, surprise surprise, my eclipse IDE let it go scott free. That might sound stupid but i cant help it
I got an output of 97 when i ran the above piece of code.
Will be thankfull to anyone who can throw some light on this
Originally posted by lhorenz baylon:
can i make a guess? maybe 97 is the ascii decimal equivalent of the letter 'a' .
That's the easy part. The hard past is why it allowed "Integer i = 'a'". Maybe the specs for autoboxing have changed a little or maybe Eclipse has got it wrong...
As far as I know Eclipse provides different graphics package (SWT) which is different than Swing.
If Integer i = 'a'; works in one implementation as you are reporting in the case of Eclipse and does not work on Sun's implementation then one of them must have a bug.