public class GenericClass {
public static void main(String... args) {
Hat<Integer> marks = new Hat<Integer>();
marks.tell(4);
Hat<String> apple = new Hat<String>();
apple.tell("apple");
}
}
class Hat<T> {
void tell(T an) {
System.out.println(an " is good");
}
void tell(String fu) {
System.out.println(fu " is healthy");
}
}
apple.tell("apple")曖昧如何?我正在嘗試檢查我可以使用多少種不同的方式來使用 Generic。
uj5u.com熱心網友回復:
apple.tell("apple")
是一個字串并且
void tell(T an) {
System.out.println(an " is good");
}
T 成為“apple”的字串,因此編譯器遇到兩個字串和多載也存在所以它是模棱兩可的
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/461561.html
上一篇:具有泛型變數的結構上的方法
