2 回答

TA貢獻(xiàn)1865條經(jīng)驗(yàn) 獲得超7個(gè)贊
/*
一個(gè)接口,如果只有一個(gè)顯式聲明的抽象方法,
那么它就是一個(gè)函數(shù)接口。
一般用@FunctionalInterface標(biāo)注出來(也可以不標(biāo))
*/
public interface Inteface1{
//可以不用abstract修飾
public abstract void test(int x,int y);
//public void test1();//會(huì)報(bào)錯(cuò),不能有兩個(gè)方法,盡管沒有使用abstract修飾
public boolean equals(Object o);//equals屬于Object的方法,所以不會(huì)報(bào)錯(cuò)
}
public class Test{
public static void main(String args[]){
Inteface1 f1=(int x,int y)->{System.out.println(x+y);};
f1.test(3,4);
Inteface1 f2=(int x,int y)->{ System.out.println("Hello Lambda!\t the result is " +(x+y));};
f2.test(3,4);
}
}

TA貢獻(xiàn)1817條經(jīng)驗(yàn) 獲得超6個(gè)贊
class Test {
static Plus add = (a, b) -> a + b;
public static void main(String args[]) {
System.out.println(add.plus(1,2));
}
interface Plus {
int plus(int a, int b);
}
}
添加回答
舉報(bào)