| advertise add site services publishers database health videos | ![]() | about toolbar stats live show health store more stuff JOIN/LOGIN |
In computer science, an object type (a.k.a. wrapping object) is a datatype which is used in object-oriented programming to wrap a non-object type to make it look like a dynamic object.[citation needed] Some object-oriented programming languages make a distinction between reference and value types, often referred to as objects and non-objects on platforms where complex value types don't exist, for reasons such as runtime efficiency and syntax or semantic issues. For example, Java has primitive wrapper classes corresponding to each primitive type: [edit] BoxingBoxing is to place a value within an object so that the value can be used as a reference object. For example, lists may have certain methods which arrays might not, but the list might also require that all of its members be dynamic objects. In this case, the added functionality of the list might be unavailable to a simple array of numbers. For a more concrete example, in Java, a To get around this, On the other hand, C# has no primitive wrapper classes, but allows boxing of any value type, returning a generic The boxed object is always a copy of the value object, and is usually immutable. Unboxing the object also returns a copy of the stored value. Note that repeated boxing and unboxing of objects can have a severe performance impact, since it dynamically allocates new objects and then makes them eligible for Garbage collection. [edit] AutoboxingAutoboxing is the term for treating a value type as a reference type without any extra source code. The compiler automatically supplies the extra code needed to perform the type conversion. For example J2SE 5.0 allows the programmer to create a This action is called autoboxing, because it is done automatically and implicitly instead of requiring the programmer to do so manually. For example, in versions of Java prior to J2SE 5.0, the following code did not compile: Integer i = new Integer(9); Integer j = new Integer(13); int k = 9 + 13; // always OK Integer l = i + j; // error in versions prior to 5.0! Compilers prior to 5.0 would not accept the last line. [edit] UnboxingUnboxing refers to a boxed value type which has been broken down and the value type retrieved for a process of some kind such as a mathematical operation. For example, in versions of Java prior to J2SE 5.0, the following code did not compile: int i = 4; int j = 5; Integer k = new Integer(i + j); // always OK Integer l = i + j; // would have been an error, but okay now - equivalent to previous line |
| ↑ top of page ↑ | about thumbshots |