title: How to change outer variable from anonymous inner class?
body: <p>I have a local variable in my outer method that I want to change from an anonymous inner class. How can I do it? </p>
  
  <p>I tried the solution using a one element array described <a href="https://stackoverflow.com/a/5977866/5372895">here</a></p>
  
  <pre><code>public class outerClass{
      static public void outerMethod(Interface interface) {
          final String[] variable = new String[1];
          new Thread(new Runnable() {
              @Override
              public void run() {
                  variable[0] = "Hello";
                  Log.i("test", variable[0]); // Works, prints "Hello"
              }
          }).start();
          Log.i("test", variable[0]); // Doesn't work, null string
      }
  }
  </code></pre>
  
  <p>and the solution using a holder described <a href="https://stackoverflow.com/a/27661758/5372895">here</a></p>
  
  <pre><code>public class outerClass{
      static public void outerMethod(Interface interface) {
          final Holder&lt;String&gt; variable = new Holder&lt;String&gt;;
          new Thread(new Runnable() {
              @Override
              public void run() {
                  variable.held = "Hello";
                  Log.i("test", variable.held); // Works, prints "Hello"
              }
          }).start();
          Log.i("test", variable.held); // Doesn't work, null string
      }
  }
  
  class Holder&lt;String&gt; {
      public String held;
  }
  </code></pre>
  
  <p>but both don't work in my case for some reason. </p>
  
  <p>It might be relevant, but what is different is that my outer method is static. I also simplified my code here,  the original code was for an anonymous Callback class from the Retrofit library on Android.</p>