I recently stumbled upon a code like the one below.
@Component
public class Instance {
private static Instance instance;
private final Template template;
public Instance(Template template) {
this.template = template;
Instance.instance = this;
}
static void someMethod() {
instance.template.doSomething();
}
}
From my understanding this is done so that you could use template in a static method but then again you could just inject the Instance class to where you need it and avoid static method altogether.
@Component
public class Instance {
private final Template template;
public Instance(Template template) {
this.template = template;
}
void someMethod() {
template.doSomething();
}
}
I am curious as to what is the use case of such pattern and if there are any alternatives to that, thanks!