I've created my own MutableInt class, which contains a primitive int and some methods for changing the value of this int or just increasing or decreasing it by 1.
I was wondering is there is any way to make this class work like the Integer class, so for example do things like:
MutableInt foo = 42;
or
MutableInt foo = new MutableInt(41);
foo++;
or
MutableInt foo = new MutableInt(42);
int bar = foo;
Is this possible in Java?
No, there's no language support for user-defined conversions in Java. Only the conversions explicitly listed in the specification are supported.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.