Reputation: 163
BufferedImage image = new BufferedImage(Defaults.SCREEN_WIDTH, Defaults.SCREEN_HEIGHT, BufferedImage.TYPE_INT_RGB);
int[] pixels = ((DataBufferInt)image.getRaster().getDataBuffer()).getData();
I found this code in an open source project and I just want to figure out what's happening. Whenever I change a value of 'pixels' it gets "written" into the buffered image. I though that because integers in Java are primitive types, not reference types, naturally, arrays of integers would be too. So I guess my question is, are all arrays reference types in Java?
Upvotes: 1
Views: 160
Reputation: 5632
As Chapter 10 of the JLS specifies:
In the Java programming language, arrays are objects (§4.3.1), are dynamically created, and may be assigned to variables of type Object (§4.3.2). All methods of class Object may be invoked on an array.
Yes, all arrays are actually objects.
Upvotes: 4
Reputation: 83
From what I see,
I assume the type "DataBufferInt" was defined in a way that it extends from "java.lang.Integer".
Later, the values are saved into the int[] in-spite of that being primitive, because of the feature of "auto-boxing" in Java.
Upvotes: 0