سؤال

It's a very simple question which I could not understand. I am still a beginner in Java.

Consider a example:

public Integer function() {
    int i=1;
    return i;
}

The return type is an Integer type and I am returning a primitive type. It is allowed by the compiler.

So the question is, how that conversion(primitive to wrapper) takes place.

I am using JDK 1.7.

هل كانت مفيدة؟

المحلول

What you are looking for is known as Autoboxing. This Oracle tutorial should shed some light on the matter.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top