I will try explain as the best I can. Let's imagine I've this class:
public class Student { public String nome; public int number; public int age; public int grade; } Now I will have an map defined like:
Map<String, Student> students; I will want to find the students with grade >= 10 and I did something like this:
public List<Student> grade() { return students.values() .stream() .filter(Student::verifyGrade) .map(Student::clone) .collect(Collectors.toList()); } Here's come the 1st problem:
- I'm getting error "incompatible types: cannot infer type-variable(s) R" on .map(Student::clone).
2nd problem: Now if I've my map defined something like: (It's just a example I was thinking), how I would filter with the same style on 1st?
Map<String, List<Student> > Thanks for your attention :)
Student::clonereturns anObject, not aStudent.clone()can only be called if overridden byStudent, we can’t say whether it returnsObjector something else. It could return anything. The absence ofimplements Cloneableat the classStudentsuggests that it is not even delegating toObject.clone()at all. But whatever it returns, it isn’t any reason for the compiler to complain at.map(Student::clone), as there is no restriction regarding what the mapping function returns.