title: No enclosing instance of type  is accessible.
body: <p>The whole code is:</p>
  
  <pre><code>public class ThreadLocalTest {
      ThreadLocal&lt;Integer&gt; globalint = new ThreadLocal&lt;Integer&gt;(){
          @Override
          protected Integer initialValue() {
              return new Integer(0);
          }
      };
  
  
      public class MyThread implements Runnable{
          Integer myi;
          ThreadLocalTest mytest;
  
          public MyThread(Integer i, ThreadLocalTest test) {
              myi = i;
              mytest = test;
          }
  
          @Override
          public void run() {
              System.out.println("I am thread:" + myi);
              Integer myint = mytest.globalint.get();
              System.out.println(myint);
              mytest.globalint.set(myi);
          }
      }
  
  
      public static void main(String[] args){
          ThreadLocalTest test = new ThreadLocalTest();
          new Thread(new MyThread(new Integer(1), test)).start();
      }
  }
  </code></pre>
  
  <p>why the following snippet:</p>
  
  <pre><code>ThreadLocalTest test=new ThreadLocalTest();
      new Thread(new MyThread(new Integer(1),test)).start();
  </code></pre>
  
  <p>cause the following error:</p>
  
  <blockquote>
    <p>No enclosing instance of type ThreadLocalTest is accessible. Must qualify the
    allocation with an enclosing instance of type ThreadLocalTest (e.g. x.new A()
    where x is an instance of ThreadLocalTest).</p>
  </blockquote>
  
  <hr>
  
  <p>The core problem is that:
  i want to initialize the inner class in the static methods.
  here are two solutions:</p>
  
  <ol>
  <li><p>make the inner class as outer class</p></li>
  <li><p>use outer reference like :</p></li>
  </ol>
  
  <p><code>new Thread(test.new MyRunnable(test)).start();//Use test object to create new</code></p>