Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Name binding
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Rebinding and mutation== Rebinding should not be confused with mutation or assignment. * ''Rebinding'' is a change to the ''referencing'' identifier. * ''Assignment'' is a change to (the referenced) variable. * ''Mutation'' is a change to an object in memory, possibly referenced by a variable or bound to an identifier. Consider the following [[Java (programming language)|Java]] code: <syntaxhighlight lang="java"> LinkedList<String> list; list = new LinkedList<String>(); list.add("foo"); list = null; { LinkedList<Integer> list = new LinkedList<Integer>(); list.add(Integer(2)); } </syntaxhighlight> The identifier <code>list</code> is bound to a variable in the first line; in the second, an object (a linked list of strings) is assigned to the variable. The linked list referenced by the variable is then mutated, adding a string to the list. Next, the variable is assigned the constant <code>null</code>. In the last line, the identifier is rebound for the scope of the block. Operations within the block access a new variable and not the variable previously bound to <code>list</code>.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)