title: Setting outer variable from anonymous inner class
body: <p>Is there any way to access caller-scoped variables from an anonymous inner class in Java?</p>
  
  <p>Here's the sample code to understand what I need:</p>
  
  <pre><code>public Long getNumber(final String type, final String refNumber, final Long year) throws ServiceException {
      Long result = null;
      try {
          Session session = PersistenceHelper.getSession();
          session.doWork(new Work() {
                  public void execute(Connection conn) throws SQLException {
                      CallableStatement st = conn.prepareCall("{ CALL PACKAGE.procedure(?, ?, ?, ?) }");
                      st.setString(1, type);
                      st.setString(2, refNumber);
                      st.setLong(3, year);
                      st.registerOutParameter(4, OracleTypes.NUMBER);
                      st.execute();
                      result = st.getLong(4) ;
                  }
              });
      } catch (Exception e) {
          log.error(e);
      }
      return result;
  }
  </code></pre>
  
  <p>The code is in a DAO service class. Obviously it doesn't compile, because it asks that <code>result</code> be final, if it is -- it doesn't compile because I try to modify a final var. I'm bound to JDK5. Other than dropping the <code>doWork()</code> altogether, is there a way to set the result value from within <code>doWork()</code>?</p>