Skip to content
Snippets Groups Projects
Commit 81568e19 authored by Goik Martin's avatar Goik Martin
Browse files

List breakup fixed

parent 2d1aedcb
No related branches found
No related tags found
No related merge requests found
......@@ -330,11 +330,7 @@ public <link
<callout arearefs="sda_inherit_fig_RectangleConstructor-2-co"
xml:id="sda_inherit_fig_RectangleConstructor-2">
<para>Processing <code language="java">width</code> and <code
language="java">h</code></para>
</callout>
<callout arearefs="sda_inherit_fig_RectangleConstructor-2-co">
<para><code language="java">eight</code> in <quote>current</quote>
language="java">height</code> in <quote>current</quote>
<classname>Rectangle</classname> constructor.</para>
</callout>
</calloutlist>
......@@ -461,12 +457,11 @@ do {
...</programlisting>
<para>On execution the string literal "secret" will be represented
as a <classname
xlink:href="javaapi://String">String</classname>
as a <classname xlink:href="javaapi://String">String</classname>
object in memory. Each new user input string will be represented
as a <emphasis>different</emphasis> <classname
xlink:href="javaapi://String">String</classname>
object in memory as well.</para>
xlink:href="javaapi://String">String</classname> object in memory
as well.</para>
<para>Unfortunately the <quote>==</quote> operator only works as
expected for the eight built in primitive <xref
......@@ -476,18 +471,17 @@ do {
identity rather than for object equality.</para>
<para>Two different <classname
xlink:href="javaapi://String">String</classname>
instances may off course be equal with respect to their
<quote>payload</quote> namely the values they both represent.
Comparing for object equality rather than for object identity in
<xref linkend="glo_Java"/> requires using the
xlink:href="javaapi://String">String</classname> instances may off
course be equal with respect to their <quote>payload</quote>
namely the values they both represent. Comparing for object
equality rather than for object identity in <xref
linkend="glo_Java"/> requires using the
<methodname>equals(...)</methodname> method instead. A
prerequisite for this to work requires the class authors
overriding the <methodname
xlink:href="javaapi://Object#equals(java.lang.Object)">Object.equals(Object
o)</methodname> method accordingly. This override does exist in
class <classname
xlink:href="javaapi://String">String</classname>.
class <classname xlink:href="javaapi://String">String</classname>.
Within the given context we may thus simply use <methodname
xlink:href="javaapi://String#equals(java.lang.Object)">String.equals(Object
o)</methodname>:</para>
......@@ -600,8 +594,7 @@ public class Run {
public static void main(String[] args) {
final Shape shape =
new Shape(<emphasis role="red">2.0</emphasis>, <emphasis
role="red">3.0</emphasis>); // Center coordinates
new Shape(<emphasis role="red">2.0</emphasis>, <emphasis role="red">3.0</emphasis>); // Center coordinates
System.out.println(shape); </programlisting></td>
<td valign="top"><screen>inherit.Shape@37d31475</screen><para>Desired:</para><screen><emphasis
......@@ -795,8 +788,7 @@ System.out.println(a.equals(b));</programlisting></td>
<tip>
<para>Take a closer look at the <classname
xlink:href="javaapi://String">String</classname>
and <classname
xlink:href="javaapi://String">String</classname> and <classname
xlink:href="javaapi://StringBuffer">StringBuffer</classname>
<xref linkend="glo_API"/> regarding the
<methodname>toString()</methodname> method.</para>
......@@ -805,8 +797,8 @@ System.out.println(a.equals(b));</programlisting></td>
<answer>
<para>The <classname
xlink:href="javaapi://String">String</classname>
<xref linkend="glo_API"/> reveals:</para>
xlink:href="javaapi://String">String</classname> <xref
linkend="glo_API"/> reveals:</para>
<screen>public boolean equals (Object anObject)
Compares this string to the specified object. The result is true if and only if the argument is
......@@ -827,8 +819,8 @@ true if the given object represents a String equivalent to this string, false ot
method is being overridden.</para>
<para>In class <classname
xlink:href="javaapi://StringBuffer">StringBuffer</classname>
we do not find any <methodname>equals()</methodname> method. Thus
xlink:href="javaapi://StringBuffer">StringBuffer</classname> we do
not find any <methodname>equals()</methodname> method. Thus
<classname
xlink:href="javaapi://Object">Object</classname>.<methodname
xlink:href="javaapi://Object#equals(java.lang.Object)">equals()</methodname>
......@@ -849,9 +841,9 @@ Returns:
true <emphasis role="red">if this object is the same as the obj argument</emphasis>; false otherwise.</screen>
<para>Thus two instances of <classname
xlink:href="javaapi://StringBuffer">StringBuffer</classname>
will be compared for object identity rather than representing the
same string value.</para>
xlink:href="javaapi://StringBuffer">StringBuffer</classname> will
be compared for object identity rather than representing the same
string value.</para>
</answer>
</qandaentry>
</qandadiv>
......@@ -1418,11 +1410,10 @@ de.hdm_stuttgart.mi.sd1.shape.model.Rectangle@2a139a55</screen>
<para>This result is due to the invocation of the <methodname
xlink:href="javaapi://Object#toString--">toString()</methodname>
method being defined in the <classname
xlink:href="javaapi://Object">Object</classname>
superclass. Override this method in
<classname>Shape</classname>, <classname>Circle</classname>
and <classname>Rectangle</classname> accordingly to
get:</para>
xlink:href="javaapi://Object">Object</classname> superclass.
Override this method in <classname>Shape</classname>,
<classname>Circle</classname> and
<classname>Rectangle</classname> accordingly to get:</para>
<screen>Circle (-2.0,-1.0), radius=3.5
Rectangle (3.0,1.0), width=1.5, height=4.4</screen>
......@@ -1879,8 +1870,7 @@ c.equals(r1): false</screen></td>
<section xml:id="sd1_inherit_sect_Override">
<title>The <classname
xlink:href="javaapi://Override">@Override</classname>
annotation.</title>
xlink:href="javaapi://Override">@Override</classname> annotation.</title>
<figure xml:id="sd1_inherit_fig_overrideToString">
<title>Overriding Object.toString()</title>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment