How does array class work in Java?(数组类在 Java 中是如何工作的?)
问题描述
在 Java 中,数组是一个类并扩展了 Object.我很想知道这个特殊的数组类.我在任何地方都找不到类定义.执行 getClass().getName() 会产生奇怪的结果.
In Java, array is a class and extends Object. I am curious to know about this special array class. I don't find the class definition anywhere. Doing a getClass().getName() gives strange result.
String[] array = new String[]{"one","two"};
System.out.println(array.getClass().getName()); // prints [Ljava.lang.String;
我想了解数组是如何在幕后工作的.数组类定义是否在 JVM 中硬编码?
I want to understand how array works under the hood. Is the array class definition hardcoded in the JVM?
这方面的任何资源、书籍、链接都会有所帮助.
Any resources, books, links on this will be helpful.
谢谢.
推荐答案
是的,基本上数组是 VM 非常熟悉的东西,就像原始类型一样.有特定的字节码指令可以处理数组——创建它们、索引它们等等.
Yes, basically arrays are something the VM knows about intimately, like the primitive types. There are specific bytecode instructions to work with arrays - creating them, indexing into them etc.
至于要了解更多信息的资源 - JVM 规范 可能是最好的初始点.第 7.9 节有一些字节码使用数组的示例.
As for resources to find out more - the JVM specification is probably the best starting point. Section 7.9 has some examples of bytecode working with arrays.
这篇关于数组类在 Java 中是如何工作的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:数组类在 Java 中是如何工作的?


- C++ 和 Java 进程之间的共享内存 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01