this引用当前
Object的参考。
阅读本文以获得更多理解。
通过链接给出一个例子:
public class Point { public int x = 0; public int y = 0; //constructor public Point(int x, int y) { this.x = x; this.y = y; }}在这里,为了
x与
Point和
x的区别,您需要告诉编译器区别。您可以使用实现此目标
this。意思是,当我写
this.x这本书的时候,它意味着特定的
x事物属于电流
Object,在这种情况下是
Point。
以您提供的代码为例:
alertDialog.Builder(this)
alertDialog.Builder()
Context在其构造函数中将a
作为参数。但是在这里,您不需要
Context someContext = newContext();将其作为参数传递,因为您只需要传递当前
Activity的即可
Context。因此,您只需使用
this。



