In java is a special citation, there are three main uses: ① refers to the object itself, and the syntax is this ② access the class member variables and member methods ③ swap with overloaded constructor of the class to ask here is this is what kind of usage?<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Because this code is pointing to itself in XXX extends Activity class that is written in this point Activity Context
Reply:
That is how he constructor like?
Reply:
Since there is inheritance and Activity class constructor call him what order, how to achieve the constructor
Reply:
Look Activity Activity class inheritance structure that is a subclass of Context class.
new TextView (Context context), the constructor needs to pass a Context object, so on behalf of Activity in Activity using this instance to subclass pass the parent class is the right alternative. Of course, you can also pass parameters into any subclass a Context class, such as Application
Reply:
Pro, you want to study to understand this, or look thinking in java bar, this I think it should be the equivalent pointer to this activity, although there is no constructor for this class, public void activity () {this = activity.this;} But his parent context there, this is the package, so you can not see,,,
Reply:
But he could not find the parent class constructor in the API inside ah

Reply:
Here this means the first one: ① refers to the object itself, and the syntax is this
Because Activity is indirectly inherited from the Context class, new TextView (Context context), requires a Context type object.
The parent class subclass Activity Context turn said no pressure.
Reply:
But you look at my screenshot above, I am looking for a long API which is not found constructors with parameters
Reply:
You do not find it, this is the constructor,

Reply:
Austrian. I understand, thank you ah.
No comments:
Post a Comment