0.0. After the initial object-oriented idea, when we come into contact with classes and objects, we will inevitably come into contact with the this keyword
0.1. this keyword refers to a reference to the current object.
0.2 function of this
0.2.1. this. Attribute name
The meaning of this writing is to distinguish the problem of duplicate names of member variables (non static variables in the class) and local variables passed in the method (construction method, value passing method setValue())
We know that class variables (static variables) do not depend on classes. Class variables (static variables) are loaded first
When the class is loaded later, the methods in the class are used to construct the formal parameters in the method. Is in order of priority.
That is, when the name of this. Member variable is not added,
For example: public void setTestint(int testint) {
testint = testint;
} // He passed the formal parameter variable to himself, and the last member variable was not assigned
Execute the following code:
package bilibili.bobro.operator.test; public class ThisTest { public static void main(String[] args) { Test t=new Test(); System.out.println("t.getTestchar():"+t.getTestchar()); System.out.println("t.getTestdou():"+t.getTestdou()); System.out.println("t.getTestint():"+t.getTestint()); System.out.println("t.getTeststr():"+t.getTeststr()); } } class Test { private int testint; private boolean testboo; private String teststr; private double testdou; private char testchar; public int getTestint() { return testint; } public void setTestint(int testint) { testint = testint; } public boolean isTestboo() { return testboo; } public void setTestboo(boolean testboo) { testboo = testboo; } public String getTeststr() { return teststr; } public void setTeststr(String teststr) { teststr = teststr; } public double getTestdou() { return testdou; } public void setTestdou(double testdou) { testdou = testdou; } public char getTestchar() { return testchar; } public void setTestchar(char testchar) { testchar = testchar; } }
The console output results are as follows:
If you don't add this, then
setVal (formal parameter)
{
Formal parameter (local variable) = formal parameter (local variable)
}
Pass the argument to the formal parameter in the method, and then the formal parameter assigns its own value. The member variables in the class are not involved at all.
The arguments passed in didn't touch, so they were still empty.
Local variable: in the method definition or on the method declaration.
Local variable: in memory stack.
Local variable: exists with the method call and disappears with the method call.
If you don't add this, the local variable of others will backhand and pass it to themselves. After passing it, it will disappear and log off the memory on the memory stack.
I've been in a hundred flowers and leaves don't touch me. Your member variable SET method didn't get any value.
Just soy sauce purple~~~~
So this is very important~~
1. Operators and, or, XOR
&: bitwise AND
|: bitwise OR
^: bitwise XOR (the key lies in XOR. 0 is returned for the same, and or is performed for different)
0000 1111 11 00
^ 1111 0000 11 00
1111 1111 00 00
1010
& 0110
0010
1100
| 1010
1110
2. Modifier private public, default (default/friendly), protectedprivate Only available within the current class.
default: friend Same kind, same package available Parent child grandchildren not available
Public: public class
protected: protect yourself, friends and grandchildren?
3. Shift operator "> > and " << "
Take 11 as an example:
Binary of 11: 0000 1011 eleven
11>>1 0000 0101 5
11>>2 0000 0010 2
11<<1 0001 0110 22
11<<2 0010 1100 44
Moving right is equivalent to division, but we don't say division, because moving left and right turns into binary, and then moves left and right to supplement 0
In a computer, the speed of bit operation is greater than * / (multiplication and division)
3. Shortcut keys in eclipse:
Mastering the code compiler will help us improve ourselves faster:
In eclipse
Quickly generate ste and get methods. CTRL+SHIFT+S
Quickly copy the previous line: ctrl+Alt+down/up