title: How to cast elements in an instance of List with streams in Java 8?
body: <p>Given the code:</p>
  
  <pre><code>public Statement methodCallByName(MethodDeclaration method, String string) {
      List&lt;ExpressionStatement&gt; expressions = method.getBody().statements().stream()
                                                  .filter(s -&gt; s instanceof ExpressionStatement)
                                                  .map(ExpressionStatement.class::cast)
                                                  .collect(Collectors.toList());
      return null;
  }
  </code></pre>
  
  <p>I have the following error in Eclipse Oxygen:</p>
  
  <p><a href="https://i.stack.imgur.com/4jWXb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4jWXb.png" alt="enter image description here"></a></p>
  
  <p>Notice that <code>statements()</code> returns a <code>List</code> according to <a href="https://help.eclipse.org/neon/index.jsp?topic=%2Forg.eclipse.jdt.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fjdt%2Fcore%2Fdom%2FBlock.html" rel="nofollow noreferrer">JDT docs</a>.</p>
  
  <p>What is wrong?</p>