Java = operator

Integer n = 5;  
System.out.println(n) // 5!

How can I reproduce this behavior in my classes?

+3
source share
5 answers

You can not. This is called Autoboxing, and this feature of some classes in Java makes it easier to work with classes that represent primitive type types int.

+10
source

Depending on what kind of behavior you want, you either cannot, or you need to implement the toString () method to get print (ln) to print a text representation of your object.

+2
source

Java.

+1

You cannot overload operators in Java. The Sun guys decided that they would do it for several classes, but they won’t let you do it yourself.

+1
source

The assignment operator cannot be overloaded in java. You need to look at other languages ​​like C ++. I do not know if you can do this even there for an assignment operator.

0
source

Source: https://habr.com/ru/post/1729738/


All Articles