title: Write a Java 8 predicate that filters against a value that is not in scope
body: <p>I am trying to write a filtering predicate that will filter a list based on a value held in a different object, but the object that I want to extract the value to compare against is available at the time that the comparison is carried out, not at the time the predicate is defined.</p>
  
  <p>Here's an SSCCE</p>
  
  <pre><code>import java.util.Arrays;
  import java.util.List;
  import java.util.function.Predicate;
  public class StreamTest {
      public static void main(String [] args){
          DataContainer dc = new DataContainer();
          Predicate&lt;Integer&gt; p = new Predicate&lt;Integer&gt;(){
              @Override
              public boolean test(Integer t) {
              /********************************************/
                  return t &gt; 6; // I need this to be t &gt; the limitValue that is available when the predicate gets executed
              /********************************************/
              }
          };
  
          System.out.println(dc.numberOfValuesGreaterThan(p, new LimitValue(6)));
      }
  
  }
  class DataContainer{
      private List&lt;Integer&gt; l = Arrays.asList(new Integer[]{1,2,3,4,5,6,7,8,9,10});
  
      public long numberOfValuesSatisfyingPredicate(Predicate predicate,LimitValue lv){
          return l.stream()
                  .filter(predicate)
                  .count();
      }
  }
  class LimitValue{
      private int limitValue; 
      public LimitValue(int limitValue){
          this.limitValue = limitValue;
      }
      public int getValue(){
          return limitValue;
      }
  }
  </code></pre>
  
  <p>The code creates a DataContainer, that contains the numbers 1 - 10 and has a method that takes a Predicate and a Limit Value, allowing you to do things like get the number of elements greater than 5, or less that 9 by supplying different predicates.</p>
  
  <p>However, at the time the Predicate is defined the LimitValue object is not in scope. Is it possible to define a Predicate that can access variables that are available at execution time but not at definition time?</p>