title: How to pass variables to a Thread's Runnable created with lambda as an anonymous function?
body: <p>Either IntelliJ isn't intelligent enough and confuses me or it's more likely there's something that I'm missing about scopes of variables in Java (or the concept of OOP). I have this piece of code:</p>
  
  <pre><code>public class SomeClass {
  
      private String foo = "something";
  
      public void someMethod() {
          new Thread(() -&gt; {
              String bar = foo; // How can foo be accessed from here?
              someOtherMethod(); // Even for this IntelliJ shows no error.
          }).start();
      }
  
      public void someOtherMethod() {
          // ...
      }
  
  }
  </code></pre>
  
  <p>I think it illustrates pretty well what I'm trying to achieve: I'd like to work with the foo property of SomeClass inside that Thread. So I've just started to write my program like this, then I realized that it's not correct (or is it?) but then I was quite surprised that the editor is not complaining about foo and someOtherMethod for them being inaccessible from inside the Thread's Runnable.</p>
  
  <p>Maybe it's just me not understanding OOP entirely. Is this code really correct and it's just that foo is being passed by value into the anonymous function and someOtherMethod by reference?</p>