title: Why do these two apparently identical objects have different class types?
body: <p>I have a class <code>User</code>, only have two fields: id, name</p>
  
  <pre><code>package test;
  
  public class User {
      private Long id;
      private String name;
  
      public Long getId() {
          return id;
      }
  
      public void setId(Long id) {
          this.id = id;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  }
  </code></pre>
  
  <p>Then in the <code>Main</code> class, I tried to initialize the User object with two different approach:</p>
  
  <pre><code>package test;
  
  /**
   * @author lhuang
   */
  public class Main {
      public static void main(String[] args) {
          User u = new User() {
              {
                  setId(1l);
                  setName("LHuang");
              }
          };
  
          System.out.println(u.getClass());
  
          User u2 = new User();
          u2.setId(1l);
          u2.setName("LHuang");
          System.out.println(u2.getClass());
      }
  }
  </code></pre>
  
  <p>then I can get the output </p>
  
  <pre><code>class test.Main$1
  class test.User
  </code></pre>
  
  <p>The interesting is why the u class is the inner class type of Main? But actually I still can use the <code>u.getId()</code> and <code>u.getName()</code> method.</p>