What is the difference between object and primitive types?
Variables with object types contain references to object values. This means that after a := b the variable ‘a’ refers to the same object as variable ‘b’. Therefore changes of the object value that ‘a’ refers to, will effect variable ‘b’ as well (and vice versa) because both variables refer to the same object. For primitive types a different logic is used. Variables with primitive types contain the value itself. This means that after a := b both variables are still distinct and changing one variable has no effect on the other. If ‘a’ and ‘b’ are declared to have type ‘aType’ which contains the integer field ‘property’ you can do the following: b.property := 1; a := b; b.property := 2; Everything boils down to the question: What value does ‘a.property’ have now. • When ‘aType’ is an object type a.property has the value 2 because ‘a’ and ‘b’ both refer to the same object. • When ‘aType’ is a primitive type a.property has still the value 1 because ‘a’ and ‘b’ are distinct objects.
Related Questions
- If the ActiveSync provider supports synchronization of multiple object types, how can IReplStore::Initialize know which are enabled so it does not waste time on disabled object types?
- Where can I find the Object Codes that correspond to LCM Event Types (Earnings Codes)?
- What is the difference between object and primitive types?