In JavaScript it is easy to modify (or even replace entirely) built-in classes. One could simply write a name of a method and inject it into built-in class in JavaScript simply by typing =
and defining a function. Then this method can be used on every instance of that class.
For example, I injected a method multiply
into String
JavaScript built-in class which multiplies string which string object contains given number of times.
Can I do something similar in Java?
I know that I can extend some built-in class and in my custom class define this method. But, is it possible to inject a method in a built-in Java class like in JavaScript so that everywhere where that class is used in the program this custom method is available?