我知道静态类,方法和数据成员是什么,但我无法解释单个静态关键字的工作原理。我在谷歌上尝试了很多查询,搜索术语建议将不胜感激。
示例:
public class HibernateUtility {
private static SessionFactory sessionFactory;
private static ServiceRegistry serviceRegistry;
static
{
try {
Configuration configuration = new Configuration().configure();
serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
} catch(HibernateException e) {
System.out.println("Problem creating session factory");
}
}
}