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
d53ae92e
Commit
d53ae92e
authored
4 years ago
by
Goik Martin
Browse files
Options
Downloads
Patches
Plain Diff
Extended string copy constructor explanation
parent
dbb30ba8
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/coreClasses.xml
+59
-4
59 additions, 4 deletions
Doc/Sd1/coreClasses.xml
with
59 additions
and
4 deletions
Doc/Sd1/coreClasses.xml
+
59
−
4
View file @
d53ae92e
...
...
@@ -62,11 +62,66 @@
<figure
xml:id=
"sd1_coreclasses_fig_stringCopyConstructorApiHint"
>
<title>
String copy constructor
</title>
<programlisting
language=
"java"
>
String s = new String("Eve");
</programlisting>
<informaltable
border=
"1"
>
<tr>
<th>
Code
</th>
<th>
Output
</th>
</tr>
<tr>
<td
valign=
"top"
><programlisting
language=
"java"
>
final String s = "Eve";
<co
linkends=
"sd1_coreclasses_fig_stringCopyConstructorApiHint-1"
xml:id=
"sd1_coreclasses_fig_stringCopyConstructorApiHint-1-co"
/>
final String sCopy = new
<link
xlink:href=
"https://docs.oracle.com/javase/10/docs/api/java/lang/String.html#%3Cinit%3E(java.lang.String)"
>
String
</link>
(s);
<co
linkends=
"sd1_coreclasses_fig_stringCopyConstructorApiHint-2"
xml:id=
"sd1_coreclasses_fig_stringCopyConstructorApiHint-2-co"
/>
System.out.println("sCopy == s: " + (sCopy == s));
<co
linkends=
"sd1_coreclasses_fig_stringCopyConstructorApiHint-3"
xml:id=
"sd1_coreclasses_fig_stringCopyConstructorApiHint-3-co"
/>
System.out.println("sCopy.equals(s): " + sCopy.equals(s));
<co
linkends=
"sd1_coreclasses_fig_stringCopyConstructorApiHint-4"
xml:id=
"sd1_coreclasses_fig_stringCopyConstructorApiHint-4-co"
/></programlisting></td>
<td
valign=
"top"
><screen>
sCopy == s: false
<coref
linkend=
"sd1_coreclasses_fig_stringCopyConstructorApiHint-3-co"
/>
sCopy.equals(s): true
<coref
linkend=
"sd1_coreclasses_fig_stringCopyConstructorApiHint-4-co"
/></screen></td>
</tr>
</informaltable>
<para>
Uses constructor
<methodname
xlink:href=
"https://docs.oracle.com/javase/10/docs/api/java/lang/String.html#%3Cinit%3E(java.lang.String)"
>
public
String(String original)
</methodname>
.
</para>
<calloutlist
role=
"slideExclude"
>
<callout
arearefs=
"sd1_coreclasses_fig_stringCopyConstructorApiHint-1-co"
role=
"slideExclude"
xml:id=
"sd1_coreclasses_fig_stringCopyConstructorApiHint-1"
>
<para>
The string literal
<code
language=
"java"
>
"Eve"
</code>
corresponds to an instance of
<classname>
String
</classname>
. Its
reference is being assigned to variable
<code
language=
"java"
>
s
</code>
.
</para>
</callout>
<callout
arearefs=
"sd1_coreclasses_fig_stringCopyConstructorApiHint-2-co"
xml:id=
"sd1_coreclasses_fig_stringCopyConstructorApiHint-2"
>
<para>
A clone carrying the same value
<code
language=
"java"
>
"Eve"
</code>
is being created by virtue of the
<classname
xlink:href=
"https://docs.oracle.com/javase/10/docs/api/java/lang/String.html#%3Cinit%3E(java.lang.String)"
>
String
</classname>
class copy constructor.
</para>
</callout>
<callout
arearefs=
"sd1_coreclasses_fig_stringCopyConstructorApiHint-3-co"
xml:id=
"sd1_coreclasses_fig_stringCopyConstructorApiHint-3"
>
<para>
We indeed have two distinct objects.
</para>
</callout>
<callout
arearefs=
"sd1_coreclasses_fig_stringCopyConstructorApiHint-4-co"
xml:id=
"sd1_coreclasses_fig_stringCopyConstructorApiHint-4"
>
<para>
But both
<classname
xlink:href=
"https://docs.oracle.com/javase/10/docs/api/java/lang/String.html#%3Cinit%3E(java.lang.String)"
>
String
</classname>
instances carry the same value.
</para>
</callout>
</calloutlist>
</figure>
<figure
xml:id=
"sd1_coreclasses_fig_stringCopyConstructor"
>
...
...
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