title: is accessed from within inner class, needs to be declared final
body: <pre><code>        final int receiverUserId = sendMessageRequest.getReceiverUserId();
          final int senderUserId = sendMessageRequest.getSenderUserId();
          final int replyTo = sendMessageRequest.getReplyTo();
          final int subsiteId = sendMessageRequest.getRelatedSubsiteId();
          final String message = sendMessageRequest.getMessage();
  
  
          KeyHolder keyHolder = new GeneratedKeyHolder();
          jdbcTemplateObject.update(
                  new PreparedStatementCreator() {
  
                      public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
                          PreparedStatement ps =
                                  connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
                          ps.setInt(1, senderUserId);
                          ps.setInt(2, receiverUserId);
                          ps.setInt(3, replyTo);
                          ps.setInt(4, subsiteId);
                          ps.setString(5, message);
                          return ps;
                      }
                  },
                  keyHolder
          );
          return true;
  </code></pre>
  
  <p>In the code above, if I remove final from one of the variables that I use to set <code>PreparedStatement</code>, it says <code>"" is accessed from within inner class, needs to be declared final</code> . </p>
  
  <p>I understand java warns me to declare final, so I cannot change the variable later and break PreparedStatementCreater of which I just made an instance. I have read similar topics in stackoverflow, however I still cant understand it. I checked the function <code>ps.setInt</code>, its arguments are of type <code>int</code>. So they are passed by value. There is just no way I can change the value of them anyway. I really dont understand why I am getting warned here. Can you help me understand ?</p>