Headache Headache One:
In Java, essentially, a class is a programmer-defined type, which is a reference type (reference type), which means that a variable of that class type can refer to an instance of the class. On the surface, an object reference variable appears to hold an object, but in fact it simply contains a reference to the object. Strictly speaking, object reference variables and objects are different, objects (new Person ()), object reference variable (person p). But in most cases, this difference can be ignored. Therefore, it is easy to say that p is a person object, rather than a lengthy description, p is a variable that contains a reference to the person object. -----Java Basics P278
So, person p; P.A = 2; This is not possible, because at this time P has not pointed to any memory. Is null
So I need person P = new person ();
Instead, C + + direct person p; You can call P.A = 2;
Headache Headache Two:
The method inside Java,
Public void fuck (final StringBuilder str) { str.append ("haha"); }
This final only says that Str cannot be changed, that is, Str cannot point to other places, or it can modify the content it points to. For example, the above is OK, will be modified
But C + +
void Fun (const
It has been shown that the content of STR is immutable, as far as the point, which is a value copy, changes the impact on me. It's just a temporary change in the function.
Another example
void Fun (charconst str) { str[0] = ' 0 ';}
The pointer constant indicates that the pointer is a constant and can no longer be changed, but it is still possible to modify the value of the block of memory it points to.
Note: This time the block of memory needs to exist, if you are char * str = "liuweiming", so that it will change the error, because the string constant cannot be changed
String constants are saved in the code area
So the big difference is that the final string str, which is different from the const char * str
void Fun (char * const STR) {str[0] = ' 0 ';}
I want to talk to you about Java and C + +