If you want to call the method after creating the instance, this means that calling the method after construction is actually the stage of creating the instance. In this case, I would recommend an abstract factory design template to solve this problem. The code might look something like this:
class A { public A(Dependency1 d1, Dependency2 d2) {...} public postConstruct(RuntimeDependency dr) {...} } interface AFactory { A getInstance(RuntimeDependency dr); } class AFactoryImpl implements AFactory { @Inject public AFactoryImpl(Dependency1 d1, Dependency2 d2) {...} A getInstance(RuntimeDependency dr) { A a = new A(d1, d2); a. postConstruct(dr); return a; } }
Russell Bie May 14 '19 at 9:47 a.m. 2019-05-14 09:47
source share