I can write Integer var {get; set;}
but can not Integer var {get; set;} = 0
or
Integer var = 0 {get; set;}
Is it impossible to init field with set-get at the same line?
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.
Sign up to join this communityYou can set them in single line as well. You just need to follow the format. Which is
public class BasicProperty {
public integer prop {
get { return prop; }
set { prop = value; }
}
}
if you want to set a single element then can do this
public class BasicProperty {
public integer prop {
get ;
set { prop = value; }
}
}
You can also make them public or private
public integer Z { get; protected set; }
So there is no such limitation that you can't use them in single line.
set
use for? You can initialize them in the constructor as well.set
?Integer var{get; set{ var=0; } }