我想知道是否有一些功能可以从类似的界面生成装饰器的骨架Generate Setters and Getters.我想从接口创建一个类,该接口接受该接口的实例并实现每个方法,因为在实例上使用相同的参数调用相同的方法.我有一个丑陋的类来自我想要装饰的库,但它有~50种方法,我只想改变其中一种的功能,并希望节省一些打字.有这样的事吗?
示例,给定界面:
interface FooBar{
void foo( Object o );
Object bar();
}
Run Code Online (Sandbox Code Playgroud)
产生类似的东西:
class FooBarDecorator implements FooBar{
private final FooBar fubee;
FooBarDecorator( final FooBar fb ){
this.fubee = fb;
}
public void foo( Object o ){
this.fubee.foo( o );
}
public Object bar(){
return this.fubee.bar();
}
}
Run Code Online (Sandbox Code Playgroud)
Luk*_*der 32
是!!右键单击您的fubee成员,选择Source- > Generate Delegate Methods- >完成!虽然,我认为为了这个工作,你将不得不写
class FooBarDecorator implements FooBar {
// [...]
Run Code Online (Sandbox Code Playgroud)
让装饰器实现接口
| 归档时间: |
|
| 查看次数: |
4032 次 |
| 最近记录: |