1. There are three main applications of this keyword:
(1) This calls the attributes in this class, that is, the member variables in the class;
(2) This calls other methods in this class;
(3) This calls other constructors in this class, and should be placed in the first line of the constructor when calling.
The keyword this is used to refer to the current object. Therefore, this can be used as a prefix to refer to instance members inside the class;
This() represents calling another constructor. As for which constructor is called, it is determined based on the parameter table. This() call can only appear on the first line of the constructor.
When using the keyword this in an inner class, it refers to the object of the inner class. In order to access the outer class object, the outer class name can be used. This is generally only used in this case.
Sample code:
public class Activity extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /* Set display main.xml layout*/ setContentView(R.layout.main); /* findViewById(R.id.button) Get the button in the layout main.xml */ Button button = (Button) findViewById(R.id.button); /* Listen to the event information of the button*/ button.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { /* Create a new Intent object*/ Intent intent = new Intent(); /* Specify the class to start in the intent */ intent.setClass(Activity.this</span>, Activity.class); /* Start a new Activity */ startActivity(intent); /* Close the current Activity */ Activity.this.finish(); } }); } }The above is a related introduction to the understanding of the class name.this in the Java keyword ClassName.this introduced to you. I hope it will be helpful to you!