在他的“在Java中思考,第四版”的第428页(关于类型信息的章节)中,Bruce Eckel有以下示例:
public class Staff extends ArrayList<Position> {
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();
}
}
https://stackoverflow.com/questions/7325779
复制相似问题