Reference type

In programming language theory, a reference type is a data type that refers to an object in memory. A pointer type on the other hand refers to a memory address. Reference types can be thought of as pointers that are implicitly dereferenced.[1] The objects being referred to are dynamically allocated on the heap whereas value types are allocated automatically on the stack. In languages supporting garbage collection the objects being referred to are destroyed automatically after they become unreachable.

When a reference type variable refers to an immutable object it behaves with the same semantics as a primitive value type. The fact that the object being referred to cannot be modified by any of the references to it means the only way to change the value of the reference variable is through assignment. The use of the Number classes in the Java programming language is an example of this behavior.[2]

Language and platform support

References

  1. Robert Sebesta. Concepts Of Programming Languages, Tenth Edition, Pearson, 2012, p. 296
  2. http://docs.oracle.com/javase/tutorial/java/data/numberclasses.html


This article is issued from Wikipedia - version of the 6/22/2016. The text is available under the Creative Commons Attribution/Share Alike but additional terms may apply for the media files.