Guava recently switched to require java 8. How come classes like Maps, don't take java.util.function.Function as parameters instead of com.google.common.base.Function? com.google.common.base.Function extends java.util.function.Function so there shouldn't be any compatibility problems? What's the plan for porting? Is there a version 22.0 coming up with this approach?
Wouldn't that mean that everyone already using guava would have to re-compile their code since some of the methods now have changed? They can't simply upgrade without breaking some code.
It's the other way around. That's the set-up:
class GuavaFun extends JavaFunc {}
class JavaFunc {}
And you have this declaration:
public static void test(GuavaFun f) {
}
Calling it like this:
test(new JavaFunc());
will fail.
If you could extend JavaFun and make it:
class JavaFunc extends GuavaFun {}
then you could pass one or the other to the test method.
If you have your Functions declared pre java-8 style this will break, but a lambda will not.
public static void main(String[] args) {
java.util.function.Function<String, String> f2 = (String b) -> b.toUpperCase();
test((String a) -> a.toUpperCase());
test(f2);
}
public static void test(com.google.common.base.Function<String, String> f) {
}
The second test call will fail, while the lambda expression will not; because it is still a @FunctionalInterface
.