1 回答

TA貢獻(xiàn)1872條經(jīng)驗(yàn) 獲得超4個(gè)贊
您所做的就是在 main 方法中定義局部變量,其類型恰好與類必須實(shí)現(xiàn)的接口一致。
您必須在類中定義為該類的所有接口提供實(shí)現(xiàn)的方法。例如:
public class Driver implements Interface1, Interface2, Interface3 {
public static void main(String[] args) {
// all code in here is irrelevant to the class implementing Interface1, Interface2, Interface3
}
public void interface1Method() {
// whatever
}
public void interface2Method() {
// whatever
}
public void interface3Method() {
// whatever
}
}
請(qǐng)注意,您不能為此使用 lambda;Driver必須實(shí)際聲明其聲明正在實(shí)現(xiàn)的所有接口中缺少的方法的實(shí)現(xiàn)。
添加回答
舉報(bào)