import java.time.LocalDate ;
import java.time.chrono.IsoChronology ;
import java.util.ArrayList ;
import java.util.HashMap ;
import java.util.List ;
import java.util.Map ;
import static java.util .stream .Collectors .groupingBy ;
import static java.util .stream .Collectors .toList ;
class Person {
LocalDate birthday;
Sex gender;
Person
( String nameArg, LocalDate birthdayArg, Sex genderArg,
String emailArg
) { name = nameArg;
birthday = birthdayArg;
gender = genderArg;
emailAddress = emailArg;
}
public enum Sex {
MALE, FEMALE
}
public void printPerson( ) {
System .
out .
println ( name
+ ", " + this .
getAge ( ) ) ; }
public int getAge( ) {
return birthday.until ( IsoChronology.INSTANCE .dateNow ( ) ) .getYears ( ) ;
}
public Sex getGender( ) {
return gender;
}
return name;
}
public String getEmailAddress
( ) { return emailAddress;
}
}
class JavaLambda {
private static ArrayList< Person> members = new ArrayList<> ( ) ;
members.add ( new Person( "Fred" , IsoChronology.INSTANCE .date ( 1980 , 6 , 20 ) , Person.Sex .MALE , "fred@example.com" ) ) ;
members.add ( new Person( "Jane" , IsoChronology.INSTANCE .date ( 1990 , 7 , 15 ) , Person.Sex .FEMALE , "jane@example.com" ) ) ;
members.add ( new Person( "Mark" , IsoChronology.INSTANCE .date ( 1990 , 7 , 15 ) , Person.Sex .MALE , "mark@example.com" ) ) ;
members.add ( new Person( "George" , IsoChronology.INSTANCE .date ( 1991 , 8 , 13 ) , Person.Sex .MALE , "george@example.com" ) ) ;
members.add ( new Person( "Bob" , IsoChronology.INSTANCE .date ( 2000 , 9 , 12 ) , Person.Sex .MALE , "bob@example.com" ) ) ;
Map
< Integer , List
< String
>> collect
= members.stream ( )
.collect ( groupingBy(
Person:: getAge,
mapping( Person:: getName, toList( ) ) )
) ;
}
}
CmltcG9ydCBqYXZhLnRpbWUuTG9jYWxEYXRlOwppbXBvcnQgamF2YS50aW1lLmNocm9uby5Jc29DaHJvbm9sb2d5OwppbXBvcnQgamF2YS51dGlsLkFycmF5TGlzdDsKaW1wb3J0IGphdmEudXRpbC5IYXNoTWFwOwppbXBvcn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UFMRSwgImJvYkBleGFtcGxlLmNvbSIpKTsKCk1hcDxJbnRlZ2VyLCBMaXN0PFN0cmluZz4+IGNvbGxlY3QgPSAKICAgICAgICAgICAgbWVtYmVycy5zdHJlYW0oKQogICAgICAgICAgICAgICAgICAgLmNvbGxlY3QoZ3JvdXBpbmdCeSgKICAgICAgICAgICAgICAgICAgICAgICAgICAgUGVyc29uOjpnZXRBZ2UsCiAgICAgICAgICAgICAgICAgICAgICAgICAgIG1hcHBpbmcoUGVyc29uOjpnZXROYW1lLCB0b0xpc3QoKSkpCiAgICAgICAgICAgICAgICAgICApOwogICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbihjb2xsZWN0KTsKICAgIH0KfQ==
compilation info
Main.java:66: error: cannot find symbol
mapping(Person::getName, toList()))
^
symbol: method mapping(Person::getName,Collector<Object,CAP#1,List<Object>>)
location: class JavaLambda
where CAP#1 is a fresh type-variable:
CAP#1 extends Object from capture of ?
Main.java:66: error: invalid method reference
mapping(Person::getName, toList()))
^
non-static method getName() cannot be referenced from a static context
Main.java:65: error: invalid method reference
Person::getAge,
^
non-static method getAge() cannot be referenced from a static context
3 errors
stdout