For example if you have an integer:
int i = 9;
How can it do that? I mean the full syntax is:
int i = new Integer(9);
How does it skip the whole new Integer() part and still work?
Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
new Integer()is not a primitive; it’s a boxed primitive.Actual primitives (
int, etc) are not objects and cannot be instantiated.Note that you can also write
Integer x = 9, and the Java compiler will implicitly insertnew Integer().This is called auto-boxing.