Note that there are some explanatory texts on larger screens.

plurals
  1. POSimple tutorial example (lambda expression) doesn't run
    primarykey
    data
    text
    <p>Finally decided to start a bit of experimentation on the new features of jdk8, namely the <a href="http://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html" rel="nofollow">lambda expressions following the tutorial</a>. For convenience, I stripped-down the example, see SSCCE below. </p> <p>Typing out the predicate just runs fine, refactoring it to a lambda expression as suggested (and actually done) by Netbeans compiles (?) without errors, but doesn't run. The laconic console printout is </p> <blockquote> <p>Fehler: Hauptklasse simple.Simple konnte nicht gefunden oder geladen werden</p> </blockquote> <p>("Error: main class couldn't be found or loaded")</p> <p>Environment:</p> <ul> <li>jdk: jdk-8-ea-bin-b102-windows-i586-08_aug_2013.exe</li> <li>Netbeans 7.4 beta, bundle from 14.7.2013. Not sure if that's the latest, couldn't download from the Netbeans site (got a "content encoding error" when clicking on its download link)</li> </ul> <p>BTW, thought of using Netbeans only because it already has support for jdk8 (if not netbeans, who else ;-) - the eclipse beta preview from efxclipse has a similar issue (compiling but not running the example). So being definitely out off my comfort zone, possibly some very stupid mistake on my part... ? </p> <pre><code>package simple; import java.util.ArrayList; import java.util.List; import java.util.function.Predicate; public class Simple { /** * @param args the command line arguments */ public static void main(String[] args) { List&lt;Member&gt; members = createMembers(); // implement predicate directly, runs fine // Predicate&lt;Member&gt; predicate = new Predicate&lt;Member&gt;() { // public boolean test(Member member) { // return member.getAge() &gt;= 18; // } // }; // predicate converted to lambda, fails to run // "class couldn't be found" Predicate&lt;Member&gt; predicate = (Member member) -&gt; member.getAge() &gt;= 18; for (Member member : members) { if (predicate.test(member)) { member.printMember();; } } } public static class Member { private String name; private int age; public Member(String name, int age) { this.name = name; this.age = age; } public int getAge() { return age; } public void printMember() { System.out.println(name + ", " + getAge()); } } private static List&lt;Member&gt; createMembers() { List&lt;Member&gt; members = new ArrayList&lt;&gt;(); members.add(new Member("Mathilda", 45)); members.add(new Member("Clara", 15)); members.add(new Member("Gloria", 18)); return members; } } </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.
 

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