What are boxed types in Java
Autoboxing and unboxing are methods for the automatic 'packing' and 'unpacking' of primitive data types into reference types. v.5.0
Since version 5.0, Java has provided a mechanism that takes care of these processes automatically (Car boxing), so that the following formulations are possible:
Integer i = new integer (5);
int n = i;
Integer j = n;
Here is what happens: a Wrapper class object Integer is formed by passing the value 5 to the constructor. The primitive type n is then initialized with this object by first automatically unboxing the reference type. So there is a change in the reference type i into the primitive type, without explicit casting or unboxing having to be formulated. In the third step, the opposite way is shown: the primitive one int-Type will go through without casting Boxing in the reference type of the wrapper class Integer encapsulated again.
You have to be aware that in any case Boxing and Unboxingprocesses run in the background. It is therefore not recommended in particular for computationally intensive and / or time-critical applications.
Another treacherous peculiarity is shown e.g. in the following code examples and is intended to make it clear that - as Java recommends - all (un) boxing processes should only be carried out when absolutely necessary:
Here, boxing becomes two Integer-Objects formed, therefore their comparison false results because they are two different objects with correspondingly different storage locations.Integer i = 15; Integer j = 15; System.out.println (i == j); // true
Amazingly, the comparison of two wrapper objects created as in the previous example generates true as a result. How can this be explained?
The solution is that for values within the byte value range (-128 to 127), if they match, newly created wrapper objects are filled with existing ones, so the comparison here points to one and the same memory location. One speaks of one pool. This principle applies to all integer numeric wrapper data types inclusive Characterbut not for the floating point wrappers.
This example takes up the penultimate and demonstrates that the use of the addressed object pool only applies if the wrapper objects are not included new were formed. In this case, through new the newly formed objects inevitably each assigned new storage space.
- What is Google hiding from its users
- What is unique about poetry
- What are arterial chemoreceptors
- Why don't Christians accept Buddha?
- How do I improve my speaking skills
- How can I check my language type
- What is your Marketing Stack Toolset
- What are some ironic questions about Quora
- What is the strongest fantasy element
- Can Nepalese doctors practice in India
- Can the water crisis in India be resolved?
- What's the coolest job in marketing
- Could defecate a germ or a bacterium
- Why do people hate bottled gourd
- How common are armadillos in Texas
- How do you recognize a good tattoo
- Which is better NIFT or FDDI
- Indian hotels allow female visitors
- Hindi films are popular in Bangladesh
- Which president is your favorite
- How can I stop being ashamed every time
- 90 Mbps is a good internet speed
- Why did Talleyrand betray Napoleon
- What are the best college events