Boxing and Widening

前端 未结 7 1667
小蘑菇
小蘑菇 2020-12-30 08:22

What is the difference between these two. I know Boxing is converting primitive values to reference. What is widening. Also what should be the sequence first boxing should b

7条回答
  •  鱼传尺愫
    2020-12-30 09:16

    Widening is transforming a variable in another with a wider type.
    Widening can be done with primitive or reference types.

    For example :

    String -> Object
    int -> long

    As the JLS states :

    a boxing conversion (§5.1.7) [is] optionally followed by a widening reference conversion


    Resources :

    • JLS - Widening Primitive Conversion
    • JLS - Widening Reference Conversions

提交回复
热议问题