1

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?

4

1 Answer 1

5

You 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.

Apex properties

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.