Semaphor
Semaphor

Reputation: 1040

Exposing getter and setter from member with eclipse

I know how to generate setter and getter methods from member fields in eclipse. But is there a way to expose the setter and getter methods of a member with setter and getter?

For example if I have a class Foo:

class Foo
{
  private int val;
  public void setVal(int val)
  {
     this.val = val;
  }
  public int getVal()
  {
    return val;
  }
}

which is a member of the class Foo2:

class Foo2
{
  private Foo foo;
}

is it possible that I generate automatically with eclipse the following methods in the class Foo2?

public void setVal(int val)
{
  foo.setVal(val);
}

public int getVal()
{
  return foo.getVal();
}

Upvotes: 0

Views: 68

Answers (1)

Tagir Valeev
Tagir Valeev

Reputation: 100169

Having Foo2 class in active editor window use Source -> Generate Delegate Methods menu item. Select getVal() and setVal(int) in the resulting window:

Generate Delegate Methods

Press OK.

Upvotes: 2

Related Questions