Java – how do I implement boxing and unpacking in my own classes?

There is no operator override like I C in Java, so I can't figure out how to box / unpack my own class

For example, when we do such things, we may use integer or float for packing and unpacking:

int myVar = new Integer(25);

But how do I implement something similar in my MyObject class? (in case I want to pack the original type myself) Do you have a code example?

Solution

Automatic boxing and unpacking cannot be implemented for user - defined classes

You can certainly provide a naming method to do this However, each time you need to boxing or unboxing, you must explicitly call them

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>