在Junit中的TestResult类中有下面这样一段代码:
protected void run(final TestCase test) {
startTest(test);
Protectable p= new Protectable() {
public void protect() throws Throwable {
test.runBare();
}
};
runProtected(test, p); endTest(test);
}其中p指向一个方法, 然后方法又调用runBare(),下面的runProtected(test, p)的实现是:
public void runProtected(final Test test, Protectable p) {
try {
p.protect();

catch (AssertionFailedError e) {
addFailure(test, e);
}
catch (ThreadDeath e) { // don't catch ThreadDeath by accident
throw e;
}
catch (Throwable e) {
addError(test, e);
}
}
为什么在run中不直接调用test.runBare();而要声明个指针然后在通过两次调用调到runBare()。
请高手指点!!!