In Java, what is the API used by auto-boxing/unboxing?
PHP中文网
PHP中文网 2017-07-05 10:26:57
0
3
1184

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中文网

认证高级PHP讲师

reply all (3)
仅有的幸福

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

    巴扎黑

    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

      大家讲道理

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

        Latest Downloads
        More>
        Web Effects
        Website Source Code
        Website Materials
        Front End Template
        About us Disclaimer Sitemap
        php.cn:Public welfare online PHP training,Help PHP learners grow quickly!