First of all, in Java, the wrapper class, the Java language is an object-oriented language, but the basic data type in Java is not object-oriented, which in the actual use of a lot of inconvenience (for example, we can not directly think of the collection collections into the original type value, Because the collection only receives objects). To address this deficiency, the design class is represented by a corresponding class for each of the basic data types, so that the classes corresponding to
1. Preface: Java is a typical object-oriented programming language, but there are 8 basic data types that do not support object-oriented programming, the basic data types do not have the characteristics of objects, no properties and methods ; Java has designed corresponding classes for this 8 basic data types ( wrapper classes ), so that they convert to each other, indirect implementation of basic data types with object characteristics, enrich the basic data type operation;
Basic
In order to facilitate the development of the article, first introduced the boxing (Boxing) and unpacking (unboxing) these two nouns. NET type is divided into two types, one is the value type and the other is the reference type. The essential difference between the two types is that the value type data is allocated on the stack, and the reference type data is allocated on the heap. So if you want to put a v
Net Is divided into two types, one is a value type, and the other is a reference type. The essential difference between these two types is that the value type data is allocated on the stack, while the reference type data is allocated on the heap. Then, if you want to put a value type data on the heap, you need a boxing operation, conversely, a value type data placed on the heap is taken out, you need to do the unpacking operation. For example, for the
Concept Brief:Before packing and unpacking, simply say the value type, the reference type:Value type: Primitive Type (Sbyte,Byte, Short,Ushort,Int,Uint,Long,Ulong,Char,Float,Double,Bool,Decimal), Enumeration (enum), Structure (struct) is allocated memory in the stack and initialized at the same time to ensure that the data is not null;Reference type: class, array, interface, delegate, string, etc., allocate memory in the heap, initialize to NULL, the reference type needs garbage collection to re
IntroductionThis article mainly introduces. NET 6 Important concepts: stacks, heaps, value types, reference types, boxing, unpacking. This article begins with a description of what happens inside the compiler when you declare a variable, and then introduces two important concepts: stack and heap, and finally introduces value types and reference types, and explains some important principles about them.Finally, a simple example code is introduced to ill
1.Java data Types Before we introduce the automatic boxing and unpacking of Java, let's look at the basic data types of java.In Java, data types can be divided into two major types, Primitive type (base type) and reference type (reference type). the value of the base type is not an object , and methods such as ToString (), Hashcode (), GetClass (), Equals () of the object cannot be called. So Java provides a wrapper type for each of the basic types. A
The brand new Thai boxing role in "The King of the fight"-the near-body attack of "BA prison" has a long history, and the skill is mostly an elbow! The hot-blooded new role debuted, with a fair match network and a variety of gameplay, the hot blood test of the King of the fight will set off a new round of fighting frenzy. : The exquisite original painting of BA prison: BA prison shows the expression of "attack is the best defense ".
The brand new Thai
Content Guide
Overview
What happens behind a variable when you declare it?
Heap and Stack
Value types and reference types
What are value types and which are reference types?
Packing and unpacking
Performance issues for boxing and unpacking
I. OverviewThis article explains six important concepts: heap, stack, value type, reference type, boxing, and unpacking. This articl
IntroducedThis article will explain 6 important concepts: stacks, heaps, value types, reference types, boxing, unpacking. This article will explain what happens when you declare a variable and explain in advance two important concepts: stacks and heaps. The article clarifies some important basic information around reference types and value types. A simple example is presented to demonstrate the performance penalty caused by
Content Guide
Overview
What happens behind a variable when you declare it?
Heap and Stack
Value types and reference types
What are value types and which are reference types?
Packing and unpacking
Performance issues for boxing and unpacking
I. OverviewThis article explains six important concepts: heap, stack, value type, reference type, boxing, and unpacking. This articl
Why to translateOne is in order to feel the best foreign technology community well-known bloggers high-quality articles, and secondly is to review the right. NET Technology Foundation supplements achieves the restudying effect, finally also is in order to exercise own English reading and writing ability. Because it is the first time to translate English article (Ah, forgive me this dish than, weak explosion!) , so there will certainly be a lot of problems (some of the sentence understanding is n
Re-discussion type
Before you discuss boxing (boxing), it's important to figure out why the value type differs from the reference type.
What is the difference between an instance of a value type that contains numeric values, and an instance of a reference type that points to an object? In addition to the memory required to store objects, each object has an object header that provides basic services for ob
();}}Code Analysis:We first defined a person class that contains 2 attributes, age and name, where age is a value type, and name is a string reference typeIt then initializes 2 person classes, Zerocool and Anders, assigns values, and then modifies the age and nameAt this time, due to the characteristics of the value type, we just allocated a resource to zerocool.age on the stack, and there was no relationship between the later declared age. So age is the same.Modifying the name is not the same,
Automatic boxing and unboxing functions in fact, the compiler to help you, the compiler at compile time according to the syntax you write, decide whether to do boxing or unboxing action. For example: Integer i = 100;
The equivalent compiler automatically compiles the following syntax for you: integer i = new integer (100);
So the function of automatic boxing an
The examples in this article describe C # Boxing and unboxing operations. Share to everyone for your reference, specific as follows:
1. Boxing in C #
Boxing in C # is an implicit conversion of a value type to type object, using a copy of the value instead of a reference in the conversion process , as can be seen from the following example:
Using System;
the heap, which is more efficient than the stack, which is why Java retains the base type. The wrapper class creates objects that can be used by some useful methods provided by the API. More powerful.
2, automatic boxing and automatic unpacking
So let's analyze the process of integer i = 5;
Before jdk1.5, such code was wrong and had to be implemented through the integer i = new integer (5); After jdk1.5, Java provided the automatic
Boxing and unpacking are the actions that are performed to convert between value types and reference types.1. boxing occurs when a value type is converted to a reference type2. unpacking occurs when a reference type is converted to a value typeThe above two sentences are not difficult to understand, but deep understanding, it will take some space to explain.Let's look at what happens when we start
Boxing and unpacking are the actions that are performed to convert between value types and reference types.1. boxing occurs when a value type is converted to a reference type2. unpacking occurs when a reference type is converted to a value typeThe above two sentences are not difficult to understand, but deep understanding, it will take some space to explain.Let's look at what happens when we start
Recently asked the question, I answered yes, because. toString () Converts the value type 2 to a reference type, so boxing occurs.It's a bit inappropriate, so check out some information and refer to the discussion on the Web:The official explanation of unboxing:Boxing is the process of converting a value type to the type object or to any interface type implemented by this value Typ E. When the CLR boxes a value type, it wraps the value inside a System
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.