Well done, you’re a reference master now!
The concept of references, especially the nuances of the
string type, can be difficult to understand when they aren’t clearly visible in the code. Let the information sink in and play with some code to check your understanding. Once you get it, this concept will save you dozens of hours of debugging.
Here’s what was covered in this lesson:
stringtype is a reference type
- Strings are immutable, which means they cannot be changed after they are created
- Being immutable also means that a
stringreference will always point to the original object, so “modifying” one reference to a
stringwill not affect other references to it
- With the equality operator (
==), strings are checked for value, not referential, equality
stringvariable can be unassigned,
null, or empty. Empty strings can be represented by
""— they’re equivalent
If you’d like to read more about the
String operations and methods, the documentation has you covered. We don’t expect you to know anymore than what was covered in this lesson, but it’s here if you’re interested!
Take this course for free