java - 如何用接口方法的方法引用替换 lambda?
问题描述
如何用接口方法中的方法引用替换 lambda?
public abstract interface Job
{
public abstract String empName();
public void JobWithDesc(String title)
{
setJobValueDesc(title, empName());
}
}
public final class JobClient {
private static final Job job;
static {
job = () -> ListJob.getName;
}
public static final Job getJob() {
return job;
}
}
想用引用替换这个 (job = () -> ListJob.getName;) lambda。请帮助我
解决方案
job = "EmpApplication"::toString;
The question, though, is why you want to turn it into a method reference.
It's a simple lambda returning a String
literal. There is no method being called.
We could wrap "EmpApplication"
into a static method and refer to it or use an instance method that returns itself.
推荐阅读
- c# - 将类对象而不是实际的脚本类分配给统一 c# 中的统一游戏对象
- css - Angular 2 多选仅显示静态占位符
- java - 使用 JFrame 和布局的 GUI 计算器
- typescript - 打字稿映射元组查找类型?
- python - 如何在python中多次遍历每个单词?
- python - 熊猫数据框在给定条件下查找第一个和最后一个元素并计算斜率
- coq - Coq: (a :: L1) = (b :: L2) ⇒ a = b ∧ L1 = L2?
- spring-boot - 在 Thymeleaf 片段中传递数组作为参数
- constructor - 如何从构造函数打印对象?
- java - 为什么我的代码中出现空指针异常错误?