문제

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

How can i reproduce this behavior in my classes?

도움이 되었습니까?

해결책

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top