Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
GoikLectures
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Goik Martin
GoikLectures
Commits
729abe34
Commit
729abe34
authored
1 year ago
by
Goik Martin
Browse files
Options
Downloads
Patches
Plain Diff
Language style
parent
af2015be
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Doc/Sd1/Inheritance/inheritance.xml
+9
-8
9 additions, 8 deletions
Doc/Sd1/Inheritance/inheritance.xml
with
9 additions
and
8 deletions
Doc/Sd1/Inheritance/inheritance.xml
+
9
−
8
View file @
729abe34
...
@@ -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
i
n
general
does compare for object identity
but two
== operator
o
n
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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment