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

Cosmetics

parent 7b0b3a65
No related branches found
No related tags found
No related merge requests found
......@@ -529,13 +529,6 @@ Found: <emphasis role="red">int</emphasis></screen>
<para>In math <quote>=</quote> denotes the equality of
objects <abbrev>e.g.</abbrev> values, sets, functions and
so on.</para>
<para>More formally the expression <code
language="java">count = 4</code> is of type <code
language="java">int</code> evaluating to 4 (surprise!).
However an <code language="java">if (...)</code> operates
on <code language="java">boolean</code> values only. We
thus must not supply expressions of any other type.</para>
</glossdef>
</glossentry>
......@@ -559,15 +552,19 @@ Found: <emphasis role="red">int</emphasis></screen>
</itemizedlist>
<para>In particular an expression like <code
language="java">count == 4</code> is of type boolean:
Either <code language="java">true</code> or <code
language="java">count == 4</code> is of type boolean being
either <code language="java">true</code> or <code
language="java">false</code>.</para>
</glossdef>
</glossentry>
</glosslist>
<para>Thus <code language="java">count = 4</code> is an
expression evaluating to 4. So the code in question may be
<para>More formally the expression <code language="java">count =
4</code> is of type <code language="java">int</code> evaluating
to 4 (surprise!). However an <code language="java">if
(...)</code> operates on <code language="java">boolean</code>
values only and <code language="java">if (4)</code> thus does
not make sense at all. The code in question may therefore be
re-written as:</para>
<programlisting language="java">int count = 1;
......@@ -579,7 +576,7 @@ if (countAssignment) { <emphasis role="red">// Error: An int is not a boolean!</
}</programlisting>
<para>Since the assignment operator is being evaluated from
right to left we do not need braces:</para>
right to left we actually do not need braces:</para>
<programlisting language="java">...
int countAssignment = count = 4; // Assigning expression count = 4 to variable countAssignment
......@@ -596,7 +593,8 @@ int countAssignment = count = 4; // Assigning expression count = 4 to variable c
final boolean test = (count == 4); // Now using "==" (comparison) in favour of "=" (assignment)
System.out.println("test=" + test);</programlisting>
<para>Again we may omit braces here:</para>
<para>Again we may omit braces here due to operator priority
rules:</para>
<programlisting language="java">...
final boolean test = count == 4; // Now using "==" (comparison) in favour of "=" (assignment)
......
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