How to implement boxing and unboxing in my own class?

前端 未结 3 853
时光说笑
时光说笑 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:56

    There is no way to implement auto-boxing and auto-unboxing for a user-defined class.

    You can of course provide named methods to do the job. However, you would have to call them explicitly every time you need to box or unbox something.

提交回复
热议问题