[cdi-dev] @PostConstruct on inherited class
JJ Snyder
j.j.snyder at oracle.com
Thu Oct 11 16:53:28 EDT 2012
I'm investigating an issue dealing with @PostConstruct...
Suppose I have the following 2 classes:
public class X {
@PostConstruct
public void init() {
}
}
public class Y extends X {
@PostConstruct
public void init() {
}
}
and then in some other class I inject Y:
public class Other {
@Inject Y y;
public void foo() {
y.doSomething();
}
According to the specs it's legal to have @PostConstruct defined on both
X and Y. Also because Y defines init() it does not inherit X's init()
method (section 4.2). So when an instance of Y is created which init()
methods should be called for the @PostConstruct? What I am observing is
that Y's init() method is called twice. Is this correct? I can't find
any examples or any documentation that talks about this specific case.
thanks,
JJ
More information about the cdi-dev
mailing list