Java :静态最终字段初始化的顺序是什么?
2022-09-01 05:15:29
好吧,假设我有一个看起来像这样的类:
public class SignupServlet extends HttpServlet {
private static final Logger SERVLET_LOGGER=COMPANYLog.open(SignupServlet.class);
private static final ExceptionMessageHandler handler = new ExceptionMessageHandler();
private static final SignupServletObservableAgent signupObservableAgent =
new SignupServletObservableAgent(null, SERVLET_LOGGER);
}
我是否可以依靠类装入器按顺序初始化这些字段,以便我可以依赖SERVLET_LOGGER在注册ObservableAgent之前进行实例化?