title: Java 8 shows this error. Local variable itemList defined in an enclosing scope must be final or effectively final
body: <p>I am writing the code using java 8 but I iterate a <code>List</code> and then find <code>RestaurantOrderBook</code> using category type. and put that <code>List</code> into a <code>Map</code>. it shows this error: </p>
  
  <blockquote>
    <p>Local variable <strong>itemList</strong> defined in an enclosing scope must be final or effectively final</p>
  </blockquote>
  
  <pre><code>Query query = new Query();
  String categ = category;
  query.addCriteria(Criteria.where("restaurantId").is(restaurantId));
  
  List&lt;RestaurantOrderBook&gt; itemList = new ArrayList&lt;RestaurantOrderBook&gt;();
  itemList = mongoTemplate.find(query, RestaurantOrderBook.class);
  System.out.println("size : " + itemList.size());
  Map&lt;String , List&lt;RestaurantOrderBook&gt;&gt; map = new HashMap&lt;String , List&lt;RestaurantOrderBook&gt;&gt;();
          Arrays.asList("TakeAway", "Dining").forEach(e -&gt;{
  
  //Following line throws error:              
  List&lt;RestaurantOrderBook&gt; list  = itemList.stream().filter(a -&gt; !a.getOrderType().isEmpty() &amp;&amp; a.getOrderType().equals(e)).collect(Collectors.toList());
                  map.put(e, list);
          });
  </code></pre>
  
  <p>I have an another situation:</p>
  
  <pre><code>@Override
      public EventReportRewardsPoints eventReportRewardsPoints(String organizerId) {
          try{
              List&lt;Event&gt; listOfEvents = eventRepo.findByOrganizerId(organizerId);
              EventReportRewardsPoints eventTransReport = new EventReportRewardsPoints();
              Integer soldTics = 0;
              Double totalRevenue = 0d;
              Integer soldToday  = 0;
  
              Integer findTotalAvailableTics = 0;
              Integer findTotalQtytics = 0;
  
              for (Event event : listOfEvents) {
                  List&lt;EventTicket&gt; eventTicket = eventTicketRepo.findByEventId(event.getId());
  
                  Integer sumOfAvailabletics = eventTicket.stream()
                          .mapToInt(EventTicket::getRemainingTickets).sum();
                  findTotalAvailableTics = findTotalAvailableTics + sumOfAvailabletics;
  
                  Integer sumOfQtytics = eventTicket.stream().mapToInt(EventTicket::getQty).sum();
                  findTotalQtytics  = findTotalQtytics + sumOfQtytics;
  
                  List&lt;EventTicketBook&gt; listOfEventsTic = eventTicketBookRepository.findByEventId(event.getId());
                  for (EventTicketBook eventTicketBook : listOfEventsTic) {
                      Double sumOfSales = eventTicketBook.getTickets().stream().mapToDouble(EventTicket::getPrice).sum();
                      totalRevenue = totalRevenue + sumOfSales;
                      Date now = new Date();
                      System.out.println("create date : " + eventTicketBook.getCreateOn());
                      /*if(now.compareTo(eventTicketBook.getCreateOn()) == 0){
                          Integer sumOfSoldToday = eventTicketBook.getTickets().stream().mapToInt(EventTicket::getQty).sum();
                          soldToday = soldToday + sumOfSoldToday;
                      }*/
                  }
              }
              System.out.println("findTotalQtytics : " + findTotalQtytics);
              System.out.println("findTotalAvailableTics : " + findTotalAvailableTics);
              soldTics = findTotalQtytics - findTotalAvailableTics;
              eventTransReport.setTotalRevenue(totalRevenue);
              eventTransReport.setSoldToday(soldToday);
              eventTransReport.setTicketsSold(soldTics);
              return eventTransReport;
          }catch(Exception e ){
              e.printStackTrace();
          }
          return null;
      }
  </code></pre>
  
  <p>How do i achive this using lamda expression.??</p>