Hi all I was wondering if I could modify and recompile a Java base class?
I would like to add functions to existing classes and be able to call these functions.
For example, I would like to add a function to java.lang.String, recompile it and use it for my project:
public char[] getInternalValue(){
return value;
}
I was wondering how do we go about doing that?
What you’re referring to is called “monkey patching”. It’s possible in Java, but it isn’t advisable and the results can be… uhh interesting. You can download the source for the String class, pop it into a JAR and prepend the bootclasspath with:
to replace the built-in String class with your own.
There’s an interesting paper on this very subject here.