While I was reading the Android book, I had a question~
Usually, you find the ID of the view in the following way.
Button startButton = (Button) findViewById(R.id.startButton);
In the book, we put this in front of findViewById.
Is there a reason to add this? Is it a problem of readability?
Button startButton = (Button) this.findViewById(R.id.startButton);
This is used to refer to the object itself. The following code requires this.
// Case 1
private String param;
public Construct(String param) {
this.param = param;
}
// // Case 2
public Function() {
synchronized(this) {
...
}
}
This in the code you posted doesn't have any special meaning. The part where readability increases when using this is also a subjective area, so it is difficult to draw a line. I think it would be better to understand that this is the code writer's coding style in the code you asked.
© 2024 OneMinuteCode. All rights reserved.