我认为标题是 self 描述的,但我们举个例子
float[] shape1 = new float[4]; //Those 4 floats are XCoord,YCoord,Width,Height
float[] shape1XY = new float[2] /*I want to store here the values of the
first 2 floats from shape1
with the ability that when i change them
shape1[0] and shape1[1] are also changed */
有没有办法真正做到这一点?
最佳答案
对于原始类型这是不可能的,因为数组存储原始值本身而不是引用。您需要创建自己的类,它将封装您需要的值,然后使用自定义类的元素数组。 对于类数组存储对对象的引用,因此在这种情况下您将能够实现您想要的。
关于java - 是否可以将数组的某些值复制到另一个数组中,但具有相同的引用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53252223/