I offer you the following. Create a set of interfaces that you would like to have. for instance
public interface HeaderHolder { public void setHeader(Header header); public Header getHeader(); }
I would like your classes to implement them, i.e. you like that your class B is defined as
class B implements HeaderHolder {...}
Unfortunately, this is not the case. Now the problem!
Create facade:
public class InterfaceWrapper { public <T> T wrap(Object obj, Class<T> api) {...} }
You can implement it at this stage using a dynamic proxy. Yes, dynamic proxy uses reflection, but forget about it right now.
Once you're done, you can use InterfaceWrapper as follows:
B b = new B(); new IntefaceWrapper().wrap(b, HeaderHolder.class).setHeader("my header");
As you can see now, you can set the headers in any class you want (if it has the corresponding property). Once you are done, you will be able to test your effectiveness. If and only if the use of reflection in a dynamic proxy is the bottleneck of the implementation change for code generation (for example, based on user annotation, package name, etc.). There are many tools that can help you do this, or, alternatively, you can implement this logic yourself. The fact is that you can always change the implementation of IntefaceWrapper without changing another code.
But avoid premature optimization. Reflection works very efficiently these days. Sun / Oracle worked hard to achieve this. They, for example, create classes on the fly and cache them to make reflection faster. Therefore, probably, taking into account the full flow, the reflecting call does not take too much time.