在第428页(关于类型信息的章节)他的“Thinking in Java,第4版”中,Bruce Eckel有以下示例:
public class Staff extends ArrayList {
public void add(String title, Person person) {
add(new Position(title, person));
}
/* rest of code snipped */
也许我有点累了,但我看不到add()方法中add()的调用如何工作。我一直认为它应该有引用,或者是一个静态方法(我在ArrayList或List中找不到一个静态add())。我失踪了什么
我刚刚测试了自己,发现这样做:
// Test2.java
public class Test2 {
public void testMethod() {
testMethod2();
}
public void testMethod2() {
System.out.println("Here");
}
public static void main(String[] args) {
Test2 t = new Test2();
t.testMethod();
}
}