Isn't overloading of methods that take Functional interfaces as parameters a risky thing. What if the classes, in which these overloaded methods are present, coded much before such interfaces are actually created.
Consider this.
Most of the code in the above class is from
http://docs.oracle.com/javase/tutorial/displayCode.html?code=http://docs.oracle.com/javase/tutorial/java/javaOO/examples/Person.java ( This is copied as is-- so why the createRoster() method is in Person class and other such questions - let us ignore them for now).
Now as we see, I have two overloaded methods with the name performAction2. The only difference is one of them takes a Predicate
parameter and the other one takes Predicate2
parameter. The compiler allows this.
I created Predicate2<T>by copying the source code of Predicate<T> and changing all references of Predicate to Predicate2.
Now I can't use Lambda expressions to call them.
If I call them as follows using Lambda expression syntax,
I get the following compilation error.
The method performAction2(List<Person>, Predicate<Person>, Function<Person,Object>, Consumer<Object>) is ambiguous for the type Person.
Shouldn't the Lambda expression syntax have been different? I mean why should lambda expressions syntax have no way of specifying which interface is being implemented? What do you think?