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

Language style

parent af2015be
No related branches found
No related tags found
No related merge requests found
...@@ -521,12 +521,12 @@ System.out.println("You made it!"); ...@@ -521,12 +521,12 @@ System.out.println("You made it!");
<methodname <methodname
xlink:href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Object.html#equals(java.lang.Object)">Object.equals(Object xlink:href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Object.html#equals(java.lang.Object)">Object.equals(Object
o)</methodname> when comparing different objects for equality. The o)</methodname> when comparing different objects for equality. The
== operator in general does compare for object identity but two == operator on the other hand does compare for object identity
different objects may still be considered equal rather than semantic equality of objects based on their respective
<abbrev>e.g.</abbrev> with respect to their attributes. However attribute values. However comparing <code
comparing <code language="java">Enum</code> instances for equality language="java">Enum</code> instances for equality using the <code
using the <code language="java">==</code> operator seems to be language="java">==</code> operator seems to be sufficient<abbrev>
sufficient<abbrev> e.g.</abbrev>:</para> e.g.</abbrev>:</para>
<programlisting language="java">Day day = Day.Saturday; <programlisting language="java">Day day = Day.Saturday;
...@@ -537,7 +537,8 @@ if (day == Day.FRIDAY) ... ...@@ -537,7 +537,8 @@ if (day == Day.FRIDAY) ...
if (day.equals(Day.FRIDAY)) ...</programlisting> if (day.equals(Day.FRIDAY)) ...</programlisting>
<para>Do we thus require an <methodname>equals(Object <para>Do we thus require an <methodname>equals(Object
o)</methodname> method for comparisons? Give a precise o)</methodname> method in <code language="java">enum</code>
<classname>Day</classname> for comparisons? Give a precise
explanation.</para> explanation.</para>
</question> </question>
...@@ -545,7 +546,7 @@ if (day.equals(Day.FRIDAY)) ...</programlisting> ...@@ -545,7 +546,7 @@ if (day.equals(Day.FRIDAY)) ...</programlisting>
<para>In case of <code language="java">enum</code> instances using <para>In case of <code language="java">enum</code> instances using
the <quote>==</quote> operator is sufficient. Due to the way <code the <quote>==</quote> operator is sufficient. Due to the way <code
language="java">enum</code>'s are being constructed instance language="java">enum</code>'s are being constructed instance
creation is being limited to the underlying <code creation is limited to the underlying <code
language="java">enum</code>'s scope by its implicitly <code language="java">enum</code>'s scope by its implicitly <code
language="java">private</code> constructor. It is thus impossible language="java">private</code> constructor. It is thus impossible
creating new instances outside the respective <code creating new instances outside the respective <code
......
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