For example, I have some class Person
class Person {
private String firstName;
private String lastName;
private String street;
...
}
Also, I have a List<Person> personList
that contains some Person
objects. The goal is to put these objects to Map<Person, Timer> personMap
as keys and add new Timer()
objects as values. So each Person
has one Timer()
.
I'm, trying to do next:
personMap = personList.stream().collect(toMap(person -> person, new Timer()));
But compiler says: there is no instance(s) of type variable(s) T, U exist so that Timer conforms to Function<? super T, ? extends U>
. I've been searching here Java 8 List into Map but it doesn't work for me.
What am I missing? What's wrong with Timer()
class?