Hi guys can anyone help me with this.
Scenario:
For context please look at my older post. How to patch a Java program?
So basically in my company if I have to redeploy a program I am only allowed to update specific classes. Meaning I have to supply the compiled class to the administrator and tell them where those files should be placed.
Question:
Now my question is I have a class named ClassA that is extended by ClassB, ClassC, and ClassD. ClassA has a method named genericMethodA() whose internal implementation I would like to change.
Example
// old implementation in ClassA
public void int genericMethodA()
{
return 50;
}
// change to this implementation in ClassA
public void int genericMethodA()
{
return 100;
}
// Method in ClassB, ClassC, and ClassD
public void logB()
{
log.info(genericMethodA());
}
Will the byte code for ClassB, ClassC, and ClassD change? So if I placed the newly compiled ClassA.class in my old JAR/WAR when ClassB, ClassC, and ClassD calls genericMethodA() will it return 50 or will it return 100.
Also can anyone point out a documentation how java compiles code. For example when a class is extended does the compiler place the instructions on the subclass byte code or it just points back to the base class.
Guys please do not hesitate to comment if you need more information or clarification about my question.
No it does not.
The main things you have to watch out for when updating classes are things that are determined during compile time. This includes method overloading, which is chosen at compile time and hardcoded, and static final primitive constants, which are inlined at compile time.
But overall, Java is actually designed to support modifying some classes while leaving others untouched. There's in fact developer guides which tell you what is safe to change and what will require recompilation of dependencies.