This cannot be done because you can't add methods to existing classes in Java.
It's even more interesting because the class String
in Java is a final
class, which cannot be subclassed.
You may be interested in this Stack Overflow answer because the thing you are describing is known as monkeypatching, which is common in more dynamic languages than Java. One of the answers links to cglib, one of several libraries that do some magic with the bytecode. Try hard enough and violate basic principles and you can do quite a bit, including making 5 be 3.
Update: This question and its answers seem to address your exact question. Some of the answers are pretty creative.