Redefine/overload type casting

casting, java

Solution

This is called operator overloading. You cannot do it in Java. And it is disallowed by design as far as I'm aware. I guess you're coming from C++ or C#, where this is possible.

http://en.wikipedia.org/wiki/Operator_overloading

Problem

Every object has a toString method inherited from the Object class it extends, which can be overloaded. IS there a way to do a similar thing with objects? Here is what I want to do: int a=n+1; where n is actually an object, but when used as an int has a specific value (eg. specified in the constructor).

Original source