Commit 9294cbc2 authored by Dr. Martin Goik's avatar Dr. Martin Goik

int to Double auto boxing exercise

parent 25719248
......@@ -139,7 +139,7 @@ int iPrimitiveFromInteger = <co linkends="sd1_numbers_fig_conventional-3"
<informaltable role="slideExclude" border="1">
<informaltable border="1" role="slideExclude">
<colgroup width="50%"/>
<colgroup width="50%"/>
......@@ -194,8 +194,8 @@ int iPrimitiveFromInteger = <co linkends="sd1_numbers_fig_conventional-3"
<para>Assigning an <classname
value to a primitive <code language="java">int</code> using the
value to a primitive <code language="java">int</code> using
the <methodname
intValue()</methodname> instance method.</para>
......@@ -238,6 +238,43 @@ while (!values.empty()) {
<qandaset defaultlabel="qanda"
<title>Auto boxing int to Double?</title>
<para>Consider the following boxing conversion:</para>
<programlisting language="java">double d = 3.0;
Double dInstance = d;</programlisting>
<para>This code compiles and executes perfectly well. On contrary
the following snippet does not:</para>
<programlisting language="java">int i = 3;
Double dInstance = i;</programlisting>
<para>Explain this result. Hint: You may want to read <link
5</link> and <link
5.2</link> in particular from the <link
Java® Language Specification</link>.</para>
<para>The compiler will not perform auto boxing from
<code>int</code> do <code>Double</code>. On the other hand Double
is no subtype of Integer disallowing a widening reference
<section xml:id="sd1_numbers_sect_numberParsing">
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment