I recently went to a Java interview, and the interviewer asked me this question. I know about boxing and unboxing, but the concept of API is very vague, and I don’t even know what the API used by boxing and unboxing is. I hope someone can help me answer it
This blog is written more clearly: Java automatic boxing and unboxing and their pitfalls
Look at this piece of code first
This is the debugging result
In Java, only the same type can be directly calculated, but no transformation is performed here. When Integer and int are calculated in the third line, they will be automatically unboxed and converted to int type for calculation, and the fourth line will be converted to int calculation first. After the result is obtained, it is automatically packaged into Integer
Take integer as an example, Integer.intValue() and Integer.valueOf(int x)