title: Java: Anonymous inner class using a local variable
body: <p>How can I get the value of <code>userId</code> passed to this method in my anonymous inner subclass here?</p>
  
  <pre><code>public void doStuff(String userID) {
      doOtherStuff(userID, new SuccessDelegate() {
          @Override
          public void onSuccess() {
              Log.e(TAG, "Called delegate!!!! "+ userID);
          }
      });
  }
  </code></pre>
  
  <p>I get this error:</p>
  
  <blockquote>
    <p>Cannot refer to a non-final variable userID inside an inner class defined in a different method</p>
  </blockquote>
  
  <p>I'm pretty sure I can't assign it as final since it's a variable with an unknown value.  I had heard that this syntax does preserve scope in some way, so I think there must be a syntax trick I don't quite know yet.</p>