I can't figure out what is the object that this is reference to inside an anonymous class method.
Two examples:
- If i implement an anonymous implementation for onClick, e.g:
View.setOnClickListener(new View.onClick() {
public void onClick(View v) {
...
this. //to which object this refers?
}
}
2.If let's say i have the following interface:
interface WebResponseHandler {
public void onWebResponseFinished(String jsonString)
}
and inside some class I'm defining a variable that implements the above interface:
private onInitWebResponseHandler = new VolleyHandler.WebResponseHandler() {
public void onWebResponseFinished(String jsonString) {
.....
this // to which object this refers to?
}
}
I was surprised that in the second example the this refers to the class that
private onInitWebResponseHandler is part from and not refers to onInitWebResponseHandler directly
question from:
https://stackoverflow.com/questions/65643553/who-is-this-inside-an-anonymous-class-implementation 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…