Java doesn't support static renaming. One idea is to subclass object in question with a new classname (but may not be a good idea because of certain side-effects / limitations, e.g. your target class may have the final modifier. Where permitted the code may behave differently if explicit type checking is used getClass()
or instanceof ClassToRename
, etc. (example below adapted from a different answer)
class MyApp {
public static void main(String[] args) {
ClassToRename parent_obj = new ClassToRename("Original class");
MyRenamedClass extended_obj_class_renamed = new MyRenamedClass("lol, the class was renamed");
// these two calls may be treated as the same
// * under certain conditions only *
parent_obj.originalFoo();
extended_obj_class_renamed.originalFoo();
}
private static class ClassToRename {
public ClassToRename(String strvar) {/*...*/}
public void originalFoo() {/*...*/}
}
private static class MyRenamedClass extends ClassToRename {
public MyRenamedClass(String strvar) {super(strvar);}
}
}