Question
Integer n = 5;
System.out.println(n) // 5!
How can i reproduce this behavior in my classes?
Solution
You can't. This is called Autoboxing
, and it is a special feature of some classes in Java to ease working with classes that represent primitive types like int
.
OTHER TIPS
Depending on what behaviour you want, you either can't, or you need to implement the ‘toString()‘ method to get print(ln) to print out a textual representation of your object.
You can't overload the assignment operator in Java.
You can't overload operators in Java. The guys at Sun decided they would do it for a few classes, but they won't let you do it yourself.
The assignment operator cannot be overloaded in java. You need to look at other languages such as C++. I don't know if you can do it even there for the assignment operator.