8

I know the long hand way of doing this is as follows:

private String var1;

public String getvar1() {
 return var1;
}
public void setvar1(String str) {
 var1 = 'Prefix '+str;
}

The shorthand way is something along the lines of the following but I don't know how the value is passed:

public String var1 {
 get;
 set(String str) {
  this = 'Prefix '+str;
 }
}

As such the set is pseudocode. I would like to know the correct form for this shorthand way of writing the setter.

1

1 Answer 1

6

This should do.

public String var1 {
 get;
 set {
  var1 = value; 
 }
}

You can use 'value', which has the actual input for the setter.

This is clearly described in the documentation

1
  • 1
    Thanks, this works perfectly. I cannot mark this as the answer for another 8 minutes.
    – Venko
    Commented Feb 7, 2014 at 12:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .