I have a simple class with a property and a parent that is of the same type.

public class BasicProperty {
   private BasicProperty parentProp;
   private Integer myCounter = 0;

   public Integer prop {
      get { this.myCounter++; return this.parentProp.prop; }
      set { prop = value; }

In this example, this.parentProp will give us the value of the property, bypassing the get accessor.

Is it possible to access the value of the property of another instance using the accessor?

Of course, I could resolve this by using a wrapper method and calling it instead - but it makes the code harder to read and it's not immediately clear what is happening there in the first place.

  • Can you post the example you used to check this. I am not getting this behavior based on my check – Zach Hutchins Mar 25 at 14:26
  • I clarified the question and put in a counter to illustrate the difference between accessor vs. value. – Semmel Mar 25 at 16:58
  • Your property won't be valid you are returning BasicPropery type not integer – Zach Hutchins Mar 25 at 17:03
  • Whoops. Typo. It should be return this.parentProp.prop of course. – Semmel Mar 25 at 18:28
  • 1
    Saw your edit. I'd need to research, this is not in the docs. – sfdcfox Mar 25 at 19:03

Your Answer

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

Browse other questions tagged or ask your own question.