title: How to access fields declared inside anonymous object?
body: <p>Java lets you declare new fields inside anonymous classes, but I can't figure out how to access them from outside, even setting them to public doesn't let me.</p>
  
  <pre><code>class A {
     public static void main(String[] args) {
         Object o = new Object() {
             public int x = 0;
             {
                 System.out.println("x: " + x++);
                 System.out.println("x: " + x++);
             }
         };
         System.out.println(o.x);
     }
  }
  </code></pre>
  
  <p>I get this compiler error:</p>
  
  <pre><code>$ javac A.java &amp;&amp; java A
  A.java:10: cannot find symbol
  symbol  : variable x
  location: class java.lang.Object
         System.out.println(o.x);
                             ^
  1 error
  </code></pre>
  
  <p>Why?</p>