This question is not a duplicate
This question is not related to what "this" means in Java. It is a question about differing syntax for properties that I'm seeking to clarify based on my understanding of another language. I have been working through the android docs and saw the same property referenced differently and I wondered why.
Question
In Objective-C when a property is declared, it autosynthesizes getters and setters that are then accessed via a dot syntax like so:
self.someProperty;
However, in the background, this is really calling:
[self someProperty];
- (id) someProperty {
return _someProperty;
}
// or
[self setSomeProperty:someValue];
- (void) setSomeProperty:(id)someProperty {
_someProperty = someProperty;
}
Part of the autosynthesization also generates a variable with a '_' prefix which you can access directly. So to summarize,
_someProperty;
// and
self.someProperty;
Often refer to the same variable; however, in truth, self.someProperty
calls the method and _someProperty
accesses the memory directly. In Java, if I declare a property at the top of my file like this:
private String someStringProperty;
Is there some sort of autosynthesization in the background that would make these to statements different?
someStringProperty = new String();
// or
this.someStringProperty = new String();