Java 数组写/读操作

标签 java arrays

数组读/写本质上是原子的吗?

int[] arr = new int[10];
int[8] = 4; // This is what I'm interested in

在上面的代码中,第二行应该生成两个机器指令,例如

reg1 = reg_containing_arr_address + 32
Memcopy reg1 4

一些posts在堆栈溢出上看到这些是原子的。谁能解释一下他们怎么样?

最佳答案

The components (elements) of arrays are variables.

The result of an array access expression is a variable of type T, namely the variable within the array selected by the value of the index expression.

根据this answerint 变量的写入和读取是原子的。由于您的数组是 int 类型,因此对其的读取和写入是原子的。

关于Java 数组写/读操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28773092/

相关文章:

php - SQL : can I JOIN 2 tables according the first table "array" value?

javascript - 如何迭代和比较 JS 对象中的值?

java - Ant 找不到主类错误

java - jformattedtextfield 四舍五入数字

java - ListView 显示目录中的文件时出错

java - 编译器说方法未定义......但它是(我认为)

javascript - 使用高阶函数,如果另一个值为 true,则返回一个对象值 (JavaScript)

c# - 使用 Linq 添加数组数组的索引位置值

java - 是否存在将 Java 对象序列化为 JSON 的模式?

objective-c - Objective-C 中的可变大小数组?