search

Home  >  Q&A  >  body text

In Java, what is the API used by auto-boxing/unboxing?

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

PHP中文网PHP中文网2749 days ago1297

reply all(3)I'll reply

  • 仅有的幸福

    仅有的幸福2017-07-05 10:28:57

    This blog is written more clearly: Java automatic boxing and unboxing and their pitfalls

    reply
    0
  • 巴扎黑

    巴扎黑2017-07-05 10:28:57

    Look at this piece of code first

            Integer a = 1;
            int b = 2;
            int c = a + b;
            Integer d = a + b;


    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

    reply
    0
  • 大家讲道理

    大家讲道理2017-07-05 10:28:57

    Take integer as an example, Integer.intValue() and Integer.valueOf(int x)

    reply
    0
  • Cancelreply