[英]Are we using the adapter design pattern everytime we extend a class and implements its interfaces methods?
[英]Is it overloading if a class implements muplitple interfaces with similar methods?
我很想知道如果 class 實現兩個或多個具有相似方法的接口,是否可以將其視為方法重載。 如果不是,那么正確的術語是什么?
舉個例子
public interface I1 {
int method1(String input);
}
public interface I2 {
void method1(int input);
}
public class C1 implements I1, I2 {
public int method1(String input){ return 0;}
public void method1(int input){}
}
重載歸結為:
在 Java 中,如果參數不同(參數數量不同、參數類型不同或兩者兼有),則兩個或多個方法可能具有相同名稱。 這些方法稱為重載方法,此功能稱為方法重載。
從 這里。
因此,顯然,您的 class C1
會重載method1()
。 它這樣做是為了覆蓋這兩種方法的事實並沒有改變這一點。 如果重載也發生了,那么重載的定義並不重要。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.