I read this post: Is int an object in Java?.
In the post it is argued that int
is not inherited from Object
. If so is the case, then why does the code below compile without any error? Given that int
is not Object
and the signature of format()
method is public static String format(String format, Object... args)
as shown in documentation: javadoc for String!
public class Testing {
public static void main(String[] args) {
int integer = 7;
String str = String.format("%03d", integer);
System.out.println(str);
}
}
I have also read about "Autoboxing". What does this exactly mean? Are all the primitives replaced by appropriate Object
's before compilation? If so, then is there any advantage of memory usage while using large array of int
's (int[]
) over Integer
's (Integer[]
)? Similar arguments follow for double's etc.
Any insights are welcome.