I would like to know exactly the real space allocated in memory for an object.
I will try to explain in the following example: using a 64-bit JVM, the size of the pointer should be 8 bytes, therefore:
Object singletest = new Object(); will take 8 bytes to refer to the object plus the size of the object
Object arraytest = new Object[10]; will take 8 bytes to refer to the position where the array is stored, plus 8 * 10 bytes to store the array plus the size of each object
int singleint = new int; takes only 2 bytes, because int is a primitive typeint[] arrayint = new int[10]; will take 8 bytes for position reference and 10 * 2 bytes for elements
In addition, it is for this reason that Java allows you to write code as follows:
int[][] doublearray = new int[2][];
int[0][] = new int[5];
int[1][] = new int[10];
, , (aka pointer), , ( , ). : doublearray (8 ), - , 8 * 2 ( ) , , 2 * 5 2 * 10.
, , :
class Test {
int a, b;
int getA() {return A};
void setA(int a) {this.a = a;}
int getB() {return B};
void setB(int b) {this.b = b;}
}
, ( , Java) 8 2 + 2 .
: , ? , , , 8 ? , ?
, , ( "int i", ++, , "0" ).
... , , ! (, , , )