我是一名 C++ 程序员,当我看到下面的示例时,我正在阅读这个网站。这种技术在 Java 中叫什么?它有什么用处?
class Application {
...
public void run() {
View v = createView();
v.display();
...
protected View createView() {
return new View();
}
...
}
class ApplicationTest extends TestCase {
MockView mockView = new MockView();
public void testApplication {
Application a = new Application() { <---
protected View createView() { <---
return mockView; <--- whao, what is this?
} <---
}; <---
a.run();
mockView.validate();
}
private class MockView extends View
{
boolean isDisplayed = false;
public void display() {
isDisplayed = true;
}
public void validate() {
assertTrue(isDisplayed);
}
}
}