问题描述
如果给定一个现有的类 Foo ,假设我希望它使用委托迭代器<整数> $ c实现
Iterator< Integer>
$ c>。
-
添加委托字段
Iterator< ;整数>
和实现Iterator< Integer>
到foo
如下: p>
public class Foo implements Iterator< Integer> {
迭代器<整数>迭代器
}
-
选择源菜单,然后选择生成代理方法。
-
检查迭代器框,然后单击确定。所得到的代码将如下所示(取决于您的格式设置)。
public class Foo {
Iterator< Integer> ;迭代器
public boolean hasNext(){return iterator.hasNext(); }
public Integer next(){return iterator.next(); }
public void remove(){iterator.remove();
}
What is the fastest way in Eclipse to implement a new interface and generate delegate implementations to an existing class?
For instance given an existing class Foo
, suppose I want it to implement Iterator<Integer>
using a delegate Iterator<Integer>
.
Add the delegate field
Iterator<Integer>
and theimplements Iterator<Integer>
tofoo
as follows:public class Foo implements Iterator<Integer> { Iterator<Integer> iterator; }
Select the source menu and then "Generate Delegate Methods".
Check the iterator box and click OK. The resulting code will look as follows (depending on your formatting settings).
public class Foo { Iterator<Integer> iterator; public boolean hasNext() { return iterator.hasNext(); } public Integer next() { return iterator.next(); } public void remove() { iterator.remove(); } }
这篇关于如何添加一个代理实现的接口到一个类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!