示例类:
public class Example {
public boolean exampleMethod() {
return false;
}
}
所以,现在我想添加一个Builder类(当然我的Example类中有更多东西)。在那里,我想覆盖exampleMethod()
方法。
所以我想做这样的事情:
ExampleBuilder builder = new ExampleBuilder();
//override method
生成器:
public class ExampleBuilder {
//somehow override the exampleMethod with
//given arguments (I could do it with
//ExampleBuilder extends Example
//but I don't think that is right)
}
提前感谢您的回答!
答案 0 :(得分:2)
您可以从界面覆盖方法声明,因此您可以使用:
interface Example {
public boolean exampleMethod();
}
class ExampleBuilder implements Example{
@Override
public boolean exampleMethod() {
///
}
}