当我有两个同名方法时,如何在 JAVA 中指定 lambda 表达式?
Java8
package com.gsy;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.ResourceBundle;
public class EmailProperty {
public static void main(String args[]) {
}
interface qqq{
int a(int a);
}
interface ppp{
int a(int b);
}
class test{
int a;
int b;
int testa(int a,int b,qqq qqq){
return 1;
}
int testa(int a,int b,ppp ppp){
return 1;
}
}
public EmailProperty() {
test aaa = new test();
aaa.a = 1;
aaa.b = 2;
aaa.testa(1, 2,new ppp() {
@Override
public int a(int b) {
// TODO Auto-generated method stub
return 0;
}
});
aaa.testa(1, 2,???);
}
}
我可以在???中写什么,不需要使用匿名函数。我在使用lambda时找不到任何指定ppp或qqq的方法。
最佳答案
你可以投:
aaa.testa(1, 2, (qqq) i -> 0);
aaa.testa(1, 2, (ppp) i -> 0);
或者使用一个变量:
qqq q = i -> 0;
aaa.testa(1, 2, q);
关于java - 当我有两个同名方法时,如何在 JAVA 中指定 lambda 表达式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55970005/