Note that there are some explanatory texts on larger screens.

plurals
  1. POJava 8 sum and total not found
    primarykey
    data
    text
    <p>EDIT: Found the solution here: <a href="http://www.dreamsyssoft.com/java-8-lambda-tutorial/map-reduce-tutorial.php">http://www.dreamsyssoft.com/java-8-lambda-tutorial/map-reduce-tutorial.php</a></p> <p>I'm following this tutorial:</p> <p><a href="http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/Lambda-QuickStart/index.html">http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/Lambda-QuickStart/index.html</a></p> <p>When I get to the part where it's using the sum and average functions, I get the following error:</p> <pre><code>UserAverageTest.java:68: error: cannot find symbol double average = users.parallelStream().filter(u -&gt; u.age &gt; 0).map(u -&gt; u.age).average().getAsDouble(); ^ symbol: method average() location: interface Stream&lt;Double&gt; </code></pre> <p>I get the same error when calling sum. For some reason it appears that it's using the Stream instead of DoubleStream class. I'm using the latest jdk with lambda enabled that is linked in the tutorial.</p> <p>Has anyone hit this issue as well and was able to resolve it?</p> <p>Here is a simple example that reproduces the problem:</p> <pre><code>class User { double age; public User(double age) { this.age = age; } double getAge() { return age; } } public static void main(String[] args) throws Exception { List&lt;User&gt; users = Arrays.asList(new User(10), new User(20), new User(30)); double average = users.parallelStream() .filter(u -&gt; u.age &gt; 0) .map(u -&gt; u.age) .average() .getAsDouble(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload