Question

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.

Était-ce utile?

La solution

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

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top