• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

aliasing and immutable types

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Below is the text taken form MIT OCW 6.170

Why would a language have immutable types? Because aliasing is complicated, and when you use immutable types, the issue doesn�t arise. Also, code built with immutable types can sometimes be more efficient.



Where aliasing is defined as two reference variables pointing to same object.
So we can have aliasing that is two reference variables for same immutable object so i can't understand why "the issue doesn't arise".
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What they mean with "aliasing is complicated" is the following: If you have two variables that refer to the same object, and you change the object through one of the variables, then you will see the change also if you refer to the object through the other variable - which can be confusing. A simple example:

This can't happen with immutable types - immutable means that you cannot change the object after creating it, so you don't get surprises like this when you have multiple variables referring to the same object.
[ April 22, 2008: Message edited by: Jesper Young ]
 
Prahlad Joshi
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks sir for your nice explanation.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic