Do autoboxing and unboxing behave differently in Java and C# -
I'm manually converting from Java (1.6) to C # and for the preferences (int and double) I'm looking for some difficulty. In C #, it appears that almost all conversions are automatically
list & lt; Double & gt; List 1 = New list & lt; Double & gt; (); // Legal, C # double d0 = 3.0; List1.Add (D0); // Legal, C # Double DD = 2.3F; // Legal, C # list 1. Add (DD); // Legal, C # list & lt; Double & gt; List2 = New list & lt; Double & gt; (); // Legal, C # double D1 = 3.0; List2.Add (D1); // Legal, C # list2.Add (2.0); // legal, c # double d2 = list2.get (0); // legal, c #
but only some permissions in Java
list & lt; Double & gt; List1 = New Arrestist & lt; Double & gt; (); // Invalid, Java List & lt; Double & gt; List2 = New Arrestist & lt; Double & gt; (); // Legal, Java Double D1 = 3.0; List2.add (d1); // Legal, Java list2.add (2.0); // legal, java double d2 = list2.get (0); // Legal, Java
I would be grateful for a systematic analysis of the differences and any underlying reasoning.
In your C # example, there are no boxing or unboxing (and autoboxing) double < There is an alias for / code> only
struct
double
.
In Java, due to the Boxing Required, you can list & lt; Double & gt;
, only list & lt; Double & gt;
On compile time, list
becomes list
list & lt; Object & gt;
Or assign an original variable to an element in the list.
Comments
Post a Comment