Gen's handling of arrays array

Source: Internet
Author: User

For example, the following:

public void T () {string[][] a = new string[][] {                  {"x", "Y"}              }; String[] B = new STRING[10]; String[] C = new string[] {"x", "Y"}; String[] D = {"X", "Y"};}

Where a is the same as the class content generated by the following statement:

string[][] A2 =  {{"x", "Y"}};

When initializing an array at creation time, the size of the array cannot be specified and an error is given below:

String[] C = new String[2] {"x", "Y"}; string[][] A1 = new string[2][] {{"x", "Y"}};

Eclipse Compiler Error: cannot define dimension expressions when a array initializer is provided

The resulting class content is as follows:

public void t (); Flags:acc_public code:stack=7, locals=5, args_size=1//Create the length of the first array 0:iconst_1//Create one-dimensional array, because there is only one element in the initialization module     , {"X", "Y"} 1:anewarray #2//Class "[Ljava/lang/string;"] 4:dup 5:iconst_0//Represents the No. 0 index of a two-dimensional array to be placed in a one-dimensional array value 6:iconst_2//Because the length of the one-dimensional array {"x", "Y"} is 2, so load the constant 2 7:ane Warray #3//class java/lang/string 10:dup 11:iconst_0//Location of the one-dimensional array index 0 storage x 12:LDC #4//S Tring x 14:aastore 15:dup 16:iconst_1//Store y 17:ldc #5//String y 19:aasto position in one-dimensional array index 1     Re 20:aastore 21:astore_1//Create a second array 22:bipush 24:anewarray #3//Class java/lang/string 27:astore_2//Create a third array 28:iconst_2 29:anewarray #3//class java/lang/string 32:dup 33:ic     ONST_0 34:LDC #4//String x 36:aastore 37:dup 38:iconst_1 39:ldc #5//String y 41:aastore 42:astore_3//Create a fourth array 43:iconSt_2 44:anewarray #3//class java/lang/string 47:dup 48:iconst_0 49:ldc #4//String X 51:aastore 52:dup 53:iconst_1 54:ldc #5//String y 56:aastore 57:astore 4 59: Return

Let's start with a detailed analysis of the first array creation process:

0:iconst_1  1:anewarray     #2                  //Class "[Ljava/lang/string;] 4:dup 5:iconst_0  6:iconst_2 7:anewarray     #3                  //class JAVA/LANG/STRING10:DUP11:ICONST_012:LDC           #4 
    //string X14:AASTORE15:DUP16:ICONST_117:LDC           #5                  //String y19:aastore20:aastore21:astore_1

The first array has the following tree structure:

The specific implementation process is as follows:

0:iconst_1
Call the Load method of Immediateitem (1) to load the constants into the Operation Stack

1:anewarray #2//Class "[Ljava/lang/string;"]
The one-dimensional array type is deposited into the constant pool and pressed into the stack directly into the array type string[]

4:dup
Generates a Stackitem (Object) and calls its duplicate () method

5:iconst_0
Call the Load method of Immediateitem (0) to load the constants into the Operation Stack

6:iconst_2
Call the Load method of Immediateitem (2) to load the constants into the Operation Stack

7:anewarray #3//Class java/lang/string
The string type is deposited into the constant pool and pressed into the stack directly into the type string

10:dup
Generates a Stackitem (Object) and calls its duplicate () method

11:iconst_0
Call the Load method of Immediateitem (0) to load the constants into the Operation Stack

12:LDC #4//String X
Call the Load method of Immediateitem ("X") to load the constant into the Operation Stack
14:aastore
Create and Invoke Indexeditem (object) and call its store () method

15:dup
16:iconst_1
17:LDC #5//String y
19:aastore


20:aastore
Returns Stackitem (object) for the following execution code
21:astore_1
Create and Invoke Indexeditem (object) and call its store () method

  

  

 

Gen's handling of arrays array

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.