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
/*jdk5.0 new features: The following features are appropriate for the JDK1.5 version. All versions including 1.5jdk1.4, including 1.4, cannot use the following features. Auto-boxing (auto_boxing) and auto-unpacking (auto_unboxing) */publicclassintegertest05{publicstaticvoid Main (String[]args) {//jdk5.0 before .//int-->integer (boxed) Integeri1=newinteger ( ;//integer-->int (unboxing) inti2=i1.intvalue ();//jdk5.0, including 5.0integeri3= 10;//Automat
Automatic Boxing and unpacking mechanism introduced in Java 1.5 Auto-Boxing: (See Code)Automatic unpacking: (see Code)Note: Automatic boxing and unpacking is done by the compiler, and the compiler determines whether boxing and unboxing are performed at compile time based on syntax.Java uses the automatic
Test code:System.out.println (0L = = 0);//trueSystem.out.println (((Long) 0L). Equals (0));//falseInteger i1 = 100;Integer i2 = 100;Integer i3 = 1000;//if the int values between-128 and 127,VM use the same object, the new object is created.Integer i4 = 1000;System.out.println (I1==I2);//trueSystem.out.println (I3==I4);//falseAutoboxing and unboxing also known as unpacking and boxing, simply speaking, is to convert from primitive to wrapper class, such
reference type and a value type. The data types in net
This article will explain. NET of six important concepts, they are stack, heap, value type, reference type, boxing and unpacking. First, explain what happens in memory when you declare a variable, then introduce two important conceptual stacks and heaps, then describe the value types and reference types, and at the end of the article use examples to illustrate the effects of
The basic types and wrapper classes often need to be converted to each other, in the case of an Integer (the operation of several other packaging classes is similar):With the introduction of the automatic boxing and unpacking mechanism in JDK1.5 , the conversion between the wrapper class and the base type is easier and more convenient.So what is packing and unpacking? Let's look at each other. Boxing: conve
I. In the gas refining stage and breathing techniques, the first thing to do is to temper the air, and the second is to train the muscles and joints to develop toughness. If you only pursue the boxing form without combining the practice of refining the gas, I am afraid there will be no success in the future. It will have little effect on removing illness and extending the life of the year, and the boxing sk
Double
2. Talking about unpacking and packingBoxing is a variable that assigns an original data type to the corresponding encapsulated class. Unpacking is a variable that assigns a wrapper class variable to the corresponding primitive data type.The automatic boxing and unpacking mechanism is introduced in Java 1.5:(1) Auto-Boxing: The basic types are wrapped with their corresponding reference
Visual C # Boxing and unboxing research
2004-09-15 Author: Origin: CSDN
Before we begin to discuss this issue, we may wish to ask a few questions to systematically understand the subject we are exploring today.
The viewer may have used countless classes, such as the System.Console class or the. NET class library, many times. So, what I want to ask is where do they come from? How does C # contact them? Is there a mechanism or type system that support
Information Leakage Prevention is an overall solution that includes encryption, management, auditing, monitoring, and other aspects. Information Leakage Prevention requires "Combination boxing ". However, whether it is encryption, management, audit or monitoring, there are single-function products on the market. In this regard, are enterprises buying multiple single-function products combined into an information leakage prevention system, or are they
If the code causes the compiler to be boxed repeatedly, it can be changed to manual boxing, so that the code executes faster, see the following code:
Manual boxing Int32 v = 5; Because of string. The parameter of format is type object, so this will cause three boxing. Console.WriteLine (String. Format ("{0},{1},{2}",
What is automatic packing unpacking
Automatic boxing (autoboxing), unpacking (unboxing) of the basic data type is a feature that has been available since J2SE 5.0.Generally we want to create an object instance of a class, we do this:Class A = new Class (parameter);When we create an integer object, we can do this:Integer i = 100; (Note: not int i = 100;)In fact, the system executes for us when executing the above code: Integer i = integer.valueof
After the Java SE 1.5 release and later, the automatic boxing feature is available.Auto-boxing, "wrapping" the underlying type into one type:Basic Type-wrapper classThe following procedure triggers an automatic boxing process:Integer count = 1;Double amount = 2.0D From the Javadoc API, the wrapper class provides a way to manipulate the underlying type of encapsu
Ext.: http://www.cnblogs.com/danne823/archive/2011/04/22/2025332.html
What is automatic packing unpacking
Automatic boxing (autoboxing), unpacking (unboxing) of the basic data type is a feature that has been available since J2SE 5.0.Generally we want to create an object instance of a class, we do this:Class A = new Class (parameter);When we create an integer object, we can do this:Integer i = 100; (Note: not int i = 100;)In fact, the sys
What is automatic packing unpacking
Automatic boxing (autoboxing), unpacking (unboxing) of the basic data type is a feature that has been available since J2SE 5.0.Generally we want to create an object instance of a class, we do this:Class A = new Class (parameter);When we create an integer object, we can do this:Integer i = 100; (Note: not int i = 100;)In fact, the system executes for us when executing the above code: Integer i = integer.valueof
Java provides the corresponding object type for each of the basic data types. Before Java SE5, if you were to generate an integer object with a numeric value of 7, the code example: integer i = new integer (7); Java SE5, Java provides a new syntax that simplifies the use of basic data type objects, which we call Automatic boxing (autoboxing) and unpacking (unboxing). The previous code can be simplified to integer i = 7;.The Automatic packing box unpa
【Boxing unboxing]
Boxing is the process of converting a value type to the type object or to any interface type implemented by this value type. when the CLR boxes a value type, it wraps the value inside a system. object and stores it on the managed heap. unboxing extracts the value type from the object. boxing is implicit; unboxing is explicit. the concept of
, which is unboxing.Second, unpacking and packing is how to achieveHere's an example. Public class Main { publicstaticvoid main (string[] args) { integer integer= Ten; int i=integer; }}Get the following after you decompileFrom the results of the anti-compilation can be seen in the boxed integer integer.valueof and unpacking with Integer.intvalue.So you can summarize the process of packing and unpacking in a sentence:The boxing
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.