java - lambda, netbeans, Error: incompatible Types error -
i'm checking simple lambda expressions , have found in net next example, supposed work.
unfortunatelly, seems netbeans 8.0.1 not code in line (person p) -> p.getage() < 18)
, .map((person p) -> p.getname())
the error "incompatible parameter types in lambda expression" shown.
anybody has thought how can right problem?
public class lambda { private enum gender { male, female }; public static class person { private final string name; private final int age; private final gender gender; public person(string name, int age, gender gender) { this.name = name; this.age = age; this.gender = gender; } public string getname() { homecoming name; } public int getage() { homecoming age; } public gender getgender() { homecoming gender; } } public static void main(string[] args) { list<person> persons = new arraylist<>(); persons.add(new person("angelo", 50, lambda.gender.male)); persons.add(new person("paolo", 10, lambda.gender.male)); persons.add(new person("giuseppe", 5, lambda.gender.male)); persons.add(new person("andrea", 22, lambda.gender.female)); persons.add(new person("guglielmo", 2, lambda.gender.female)); printnames(persons, (person p) -> p.getage() < 18); } private static void printnames(list<person> persons, predicate predicate) { persons.stream() .filter(predicate) .map((person p) -> p.getname()) .sorted() .foreach(name -> system.out.println(name)); } }
i suggest alter signature of method :
private static void printnames(list<person> persons, predicate predicate)
to
private static void printnames(list<person> persons, predicate<person> predicate)
your stream<person>
created within method expects predicate<person>
filter
method.
java netbeans lambda java-8
No comments:
Post a Comment