Content deleted Content added
mNo edit summary |
No edit summary |
||
Line 20:
[[Unboxing]] redirects here, but this is about how objects work in Java. It doesn't seem to be a suitable place to put something about unboxed types in Haskell, although there is similarity in the underlying concepts. In Haskell everything by default is 'boxed', and a boxed thing could be either the thing itself or some unevaluated expression that could evaluate to something of the correct type (because Haskell is lazy). [[User:Furby100|Furby100]] ([[User talk:Furby100|talk]]) 21:15, 12 January 2008 (UTC)
Found something wrong:
<blockquote>
Another example:<br />
<br />
int i = 4;<br />
int j = 5;<br />
Integer k = new Integer(i + j); // always OK<br />
Integer l = i + j; // would have been an error, but okay now - equivalent to previous line<br />
<br />
<br />
C# does not support automatic unboxing. A boxed object must be explicitly unboxed with a typecasting operator:<br />
<br />
int i = 42;<br />
object o = i; //box<br />
int j = (int)o; //unbox<br />
Console.Writeline(j); //outputs 42<br />
</blockquote>
It is assumed that the following will compile on Java, but it won't. C# does support automatic unboxing of primitives, but not objects, just like Java.<br />
<br />
int i = 42;<br />
Object o = i; //box<br />
int j = o; //unbox<br />
System.out.println(j); //outputs "42"<br />
<br />
Will not compile because it can't unbox objects of type Object.
|