所以Java 8引入了方法引用,文档描述了这四种类型.
我的问题是两种实例类型之间的区别是什么?
- 引用特定对象的实例方法.
- 引用特定类型的任意对象的实例方法.
两者都参考参考但有什么显着不同?用于解决它们的类型推断是不同的吗?重要的是(在他们的例子中)一个是闭包而另一个是lambda?它与方法的参数数量有关吗?
只是在java中尝试了一些东西,发现了以下问题。
DefaultAndStaticMethodMain.java:8: error: not a statement
implementation1::sendNotification;
^
1 error
Run Code Online (Sandbox Code Playgroud)
以下是我的代码。
父接口:
public interface ParentInterface {
default void callForCompletion() {
System.out.println("<<<< Notification sending completed. >>>>");
}
}
Run Code Online (Sandbox Code Playgroud)
子界面:
public interface ChildInterface extends ParentInterface {
public abstract void sendNotification();
static String printNotificationSentMessage() {
return "Notification is sent successfully.";
}
}
Run Code Online (Sandbox Code Playgroud)
实施1:
public class Implementation1 implements ChildInterface {
@Override
public void sendNotification() {
System.out.println("Implementation --- 1");
System.out.println("Sending notification via email >>>");
}
}
Run Code Online (Sandbox Code Playgroud)
实施2:
public class Implementation2 implements ChildInterface {
@Override
public …Run Code Online (Sandbox Code Playgroud)