How to implement boxing and unboxing in my own class?

前端 未结 3 817
时光说笑
时光说笑 2021-01-18 21:23

In Java there is no operator overriding like i C++ so I can\'t figure out how to implement a boxing/unboxing for my own class.

For example it\'s possibile to use box

3条回答
  •  滥情空心
    2021-01-18 21:52

    autoBoxing or unboxing is available only with primitive in java like Long wrapper class for long

    Integer for int
    

    but user defiend not possible,

    best you can do constructor initialize like

    Myclass m=new Myclass(100);
    

提交回复
热议问题