In java, It is said that "every thing instantiated other than primitive type is an object."
I am trying to understand this point using below code (line 4 to be specific).
public class dummy{
public static void main(String[] args){
int[] i = new int[2];
i[0] = new Integer(3); //line 4
i[1] = 3;
System.out.println(int[].class);
System.out.println(i[0]);
}
}
After running
int[] i = new int[4];
Java is creating an object [0,0] of type class [I. The two members within this object [0,0] are primitive data type(but not reference type).
My questions:
Why does Java allow assignment of an object to primitive type member as per below line?
i[0] = new Integer(3); // object of type 'class Integer' getting assigned to i[0]How do I understand this? In counter,
i[0]displays value3but not object address.What is
Iinclass [I? I mean, forclass C{};,C[].classgivesclass [LCwhere[means "array of" andLCmeans "instance of 'class C'"
Object[] oa = new Object[3];oa[0] = 2;