Is it true that during autoboxing, the type.valueOf() method is called (which creates a new object only if another with the same primitive constant is not in the intern list. This applies to cases where interning is allowed. Otherwise, it creates a new object using new() ). Is this right ?

Is it true that during autoboxing, the type.valueOf() method is called (which creates a new object only if another with the same primitive constant is not in the intern list. This applies to cases where interning is allowed

AFAIK, the specification doesn't require anything of this sort. Yes, it requires that when boxing, cached values be used for certain cases:

If the value p being boxed is true, false, a byte, a char in the range \u0000 to \u007f, or an int or short number between -128 and 127, then let r1 and r2 be the results of any two boxing conversions of p. It is always the case that r1 == r2.

but it doesn't explicitly say that it is the "valueOf" method which would be invoked.

Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.