Gen对于数组Array的处理
举个例子,如下:
public void t() {
String[][] a = new String[][] {
{ "x", "y" }
};
String[] b = new String[10];
String[] c = new String[] { "x", "y" };
String[] d = { "x", "y" };
}
其中a如下语句生成的class内容一样,如下:
String[][] a2 = { { "x", "y" } };
当在创建时初始化数组时,不能指定数组的大小,如下会报错:
String[] c = new String[2] { "x", "y" };
String[][] a1 = new String[2][] { { "x", "y" } };
Eclipse编译器报错:Cannot define dimension expressions when an array initializer is provided
则生成的class内容如下:
public void t();
flags: ACC_PUBLIC
Code:
stack=7, locals=5, args_size=1
// 创建第一个数组
0: iconst_1 // 创建的一维数组的长度,这是因为初始化模块中只有一个元素,即{"x","y"}
1: anewarray #2 // class "[Ljava/lang/String;"
4: dup
5: iconst_0 // 表示二维数组的第0个索引上要放入一维数组值
6: iconst_2 // 由于一维数组{"x","y"}的长度为2,所以加载常量2
7: anewarray #3 // class java/lang/String
10: dup
11: iconst_0 // 在一维数组索引0的位置存储x
12: ldc #4 // String x
14: aastore
15: dup
16: iconst_1 // 在一维数组索引1的位置存储y
17: ldc #5 // String y
19: aastore
20: aastore
21: astore_1
// 创建第二个数组
22: bipush 10
24: anewarray #3 // class java/lang/String
27: astore_2
// 创建第三个数组
28: iconst_2
29: anewarray #3 // class java/lang/String
32: dup
33: iconst_0
34: ldc #4 // String x
36: aastore
37: dup
38: iconst_1
39: ldc #5 // String y
41: aastore
42: astore_3
// 创建第四个数组
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
首先来详细分析第一个数组的创建过程:
0: iconst_1 1: anewarray #2 // class "[Ljava/lang/String;" 4: dup 5: iconst_0 6: iconst_2 7: anewarray #3 // class java/lang/String 10: dup 11: iconst_0 12: ldc #4 // String x 14: aastore 15: dup 16: iconst_1 17: ldc #5 // String y 19: aastore 20: aastore 21: astore_1
第一个数组的树形结构如下:

具体执行过程如下:
0: iconst_1
调用ImmediateItem(1)的load方法将常数加载到操作栈中
1: anewarray #2 // class "[Ljava/lang/String;"
将一维数组类型存入到常量池中,直接向操作栈中压入这个数组类型String[]
4: dup
生成一个StackItem(Object)并调用其duplicate()方法
5: iconst_0
调用ImmediateItem(0)的load方法将常数加载到操作栈中
6: iconst_2
调用ImmediateItem(2)的load方法将常数加载到操作栈中
7: anewarray #3 // class java/lang/String
将String类型存入到常量池中,直接向操作栈中压入这个类型String
10: dup
生成一个StackItem(Object)并调用其duplicate()方法
11: iconst_0
调用ImmediateItem(0)的load方法将常数加载到操作栈中
12: ldc #4 // String x
调用ImmediateItem("x")的load方法将常数加载到操作栈中
14: aastore
创建并调用IndexedItem(object)并调用其store()方法
15: dup
16: iconst_1
17: ldc #5 // String y
19: aastore
20: aastore
为如下的执行代码返回StackItem(object)
21: astore_1
创建并调用IndexedItem(object)并调用其store()方法
Gen对于数组Array的处理的更多相关文章
- Java ArrayList和Vector、LinkedList与ArrayList、数组(Array)和列表集合(ArrayList)的区别
ArrayList和Vector的区别ArrayList与Vector主要从二方面来说. 一.同步性: Vector是线程安全的,也就是说是同步的,而ArrayList是线程序不安全的,不是同步 ...
- go 数组(array)、切片(slice)、map、结构体(struct)
一 数组(array) go语言中的数组是固定长度的.使用前必须指定数组长度. go语言中数组是值类型.如果将数组赋值给另一个数组或者方法中参数使用都是复制一份,方法中使用可以使用指针传递地址. 声明 ...
- javascript类型系统——数组array
× 目录 [1]创建 [2]本质 [3]稀疏[4]长度[5]遍历[6]类数组 前面的话 除了对象之外,数组Array类型可能是javascript中最常用的类型了.而且,javascript中的数组与 ...
- swift基本用法-数组array
数组简单用法 //------------------------------------------------------------------------------ // 1. 数组定义 / ...
- C#中数组Array、ArrayList、泛型List<T>的比较
在C#中数组Array,ArrayList,泛型List都能够存储一组对象,但是在开发中根本不知道用哪个性能最高,下面我们慢慢分析分析. 一.数组Array 数组是一个存储相同类型元素的固定大小的顺序 ...
- Javascript基础系列之(四)数据类型 (数组 array)
字符串,数值,布尔值都属于离散值(scalar),如果某个变量是离散的,那么任何时候它只有一个值. 如果想使用变量存储一组值,就需要使用数组(array). 数组是由多个名称相同的树值构成的集合,集合 ...
- AS3 - 数组Array的几个常用方法(附样例)
AS3 - 数组Array的几个常用方法(附样例) 2015-03-30 10:39发布:hangge浏览:241 Flex/Flash开发中,经常会使用到数组,下面总结了一些数组的常用方法. 1 ...
- Linux数组array基础
Linux数组array基础[${a[*]}和$a的区别] Bash中,数组变量的赋值有两种方法: (1) name = (value1 ... valuen) 此时下标从0开始 (2) name[i ...
- 学习Swift -- 数组(Array) - 持续更新
集合类型--数组 Array是Swift中的一种集合类型:数组,数组是使用有序列表储存同一类型的多个值,与OC的NSArray的最大不同是,Swift的数组是值类型,OC的数组是引用类型 声明数组的方 ...
随机推荐
- js常见input校验
//校验输入价格等,保留2位小数 function clearNoNum(obj){ obj.onkeyup = function(event){ var e = event || window.ev ...
- Ng第五课:Octave 教程(Octave Tutorial)
5.1 基本操作 5.2 对数据进行灵活操作 5.3 计算数据 5.4 数据可视化 5.5 控制语句和函数 5.6 矢量化 官网安装:Installation 在线文档:http://ww ...
- 1.java面向对象编程三大特性之封装
封装即把一个对象的属性.行为等放在一个实体类中隐藏起来,不允许外部对其进行修改,但是被封装的属性.行为会对外提供一个接口与外部联系,这个对外的接口通常情况下就是set().get()方法.可以通过se ...
- CentOS 6.5 伪分布安装
CentOS 6.5 伪分布安装 软件准备 jdk-6u24-linux-i586.bin .hadoop-1.2.1.tar.gz.hadoop-eclipse-plugin-1.2.1.jar ...
- hdu 4861
http://acm.hdu.edu.cn/showproblem.php?pid=4861 两个人进行游戏,桌上有k个球,第i个球的值为1^i+2^i+⋯+(p−1)^i%p,两个人轮流取,如果Do ...
- Tarjan缩点求入度为零的点的个数问题
Description: 一堆人需要联系,但如果x 可以联系 y,你联系了x就不用联系y了,你联系一个人都会有固定的花费,问你最小联系多少人,和最小花费 Solution: Tarjan缩点,求出缩点 ...
- js反选
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>& ...
- 水池问题的lua语言算法(面试题分析:我的Twitter技术面试失败了)
twitter面试题内容 “看下面这个图片” “在这个图片里我们有不同高度的墙.这个图片由一个整数数组所代表,数组中每个数是墙的高度.上边的图可以表示为数组[2,5,1,2,3,4,7,7,6]” “ ...
- ASP .Net C# ---Excel导入导出方法
导入导出的方法以及引用,可以自行创建一个帮助类 using System;using NPOI.SS.UserModel;using NPOI.XSSF.UserModel;using NPOI.HS ...
- 记一次autofac+dapper+mvc的框架搭建实践
1,环境 .net framework4.7.2,Autofac,Autofac.Mvc5,sql server 2,动机 公司项目用的是ef,之前留下代码的大哥,到处using,代码没有分层,连复用 ...