我知道如何从 Eclipse 中的成员字段生成 setter 和 getter 方法。但是有没有办法用setter和getter公开成员的setter和getter方法呢?
例如,如果我有一个类 Foo
:
class Foo
{
private int val;
public void setVal(int val)
{
this.val = val;
}
public int getVal()
{
return val;
}
}
它是 Foo2
类的成员:
class Foo2
{
private Foo foo;
}
我是否可以使用 eclipse 自动生成类 Foo2
中的以下方法?
public void setVal(int val)
{
foo.setVal(val);
}
public int getVal()
{
return foo.getVal();
}
最佳答案
在 Activity 编辑器窗口中使用Foo2
类,使用Source ->Generate DelegateMethods
菜单项。在结果窗口中选择 getVal()
和 setVal(int)
:
按“确定”。
关于java - 使用 Eclipse 公开成员的 getter 和 setter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33690941/