我正在看website上的示例代码。这是一个片段

public class ManageEmployee {
   private static SessionFactory factory;
   public static void main(String[] args) {
      try{
         factory = new Configuration().configure().buildSessionFactory();
      }catch (Throwable ex) {
         System.err.println("Failed to create sessionFactory object." + ex);
         throw new ExceptionInInitializerError(ex);
      }
      ManageEmployee ME = new ManageEmployee();

      /* Add few employee records in database */
      Integer empID1 = ME.addEmployee("Zara", "Ali", 1000);
      Integer empID2 = ME.addEmployee("Daisy", "Das", 5000);
      Integer empID3 = ME.addEmployee("John", "Paul", 10000);

为什么该类自称?看起来它只会不断地循环调用自己。该类在这里做什么ManageEmployee ME = new ManageEmployee();?谢谢。

最佳答案

main方法创建其定义的类的新实例并不少见。但是创建实例不会再次调用main。请记住,main是静态方法,不与任何特定实例绑定。

10-02 21:57