reference type
A type whose variables hold a reference, a pointer to an object stored elsewhere, rather than the value itself.
In more detail
A reference can be null, meaning it points at no object. Two references can point at the same object, so a change through one is visible through the other.
Examples
C#: classes, records, strings, arrays and delegates are reference types.Java: classes, interfaces, records, enums and arrays are reference types; using a null reference throws NullPointerException.Related terms
- value type — A type whose variables hold the data itself, so assigning one to another copies the whole value.
- heap — The area of memory where a program stores objects whose size or lifetime is not known in advance, typically reclaimed by a garbage collector.
- class — A blueprint in code that bundles data and the functions that work on it, from which objects are made.
- null-keyword — A special value meaning a reference points at nothing.
- primitive type — A basic built-in type, such as a whole number or true-or-false, whose values are held directly rather than as objects.
- null — A special value meaning no value or no object, set on purpose to show that something is empty or absent.
- object — A single thing created from a class or other type, holding its own values and able to run the type's methods.
- reference equality — Comparing two references to see whether they point to the very same object, rather than to objects with equal contents.
Taught in
- The C# Language: Types, Variables, and Flow Control — Modern .NET Core, C# & Enterprise Microservices
- Classes, Interfaces, and Object-Oriented C# — Modern .NET Core, C# & Enterprise Microservices
- Primitive And Reference Types — Modern Java: Virtual Threads & High-Throughput Services
- Promotion, Wrappers And The Math API — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Switch, Loops And Labels — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Objects, Nested Classes And Garbage Collection — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Overloading And Varargs — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Scope, var And Immutable Objects — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Inheritance, Overriding And Object's Methods — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Sealed Types, Casts And Pattern Matching — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Interfaces: Default, Static And Private Methods — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Sprint: Object-Oriented Java — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Generics, Bounds And Wildcards — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Lists, Sets, Maps, Deques And Sequenced Collections — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Sprint: Exceptions, Arrays And Collections — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Lambdas, Functional Interfaces And Method References — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Sprint: Lambdas And Streams — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Thread Safety: Locks And Atomics — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
References
- Reference types (C# reference)
- Java Language Specification, chapter 4: Types, Values, and Variables
- Java Tutorials: Primitive Data Types