Class.this 和 this 的有什么不同
转载:http://www.cnblogs.com/liwei45212/archive/2013/04/17/3026364.html
在阅读Java代码的時候
我们时会看到Class.this的使用
这个用法多用于在 nested class(内部类)中
当inner class(内部类)必顺使用到outer class(外部类)的this instance(实例)时
例:
class Outer{
String data = "外部类別";
public class Inner{
String data = "內部类別";
public String getOuterData(){
return Outer.this.data;
}
}
}
如果你的程序里面包含了内部匿名类之类,比如线程
class A {
public void callSomething(){
new Thread(){
public void run(){
// 这里的this 代表 匿名类的上下文, A.this 代表A实例化后对象的上下文
}
}.start();
}
}
随机推荐
- [Code Festival 2017 qual A] B: flip
题意 给出一个n行m列初始全白的矩阵,每次可以翻转一行/一列的全部格子的颜色.问任意次操作后能否使得恰好有k个黑色格子. n,m<=1000 分析 显然要么翻转一次要么不翻转. 最终黑色格子数只 ...
- [BZOJ1195]最短母串
1195: [HNOI2006]最短母串 Time Limit: 10 Sec Memory Limit: 32 MB Description 给定n个字符串(S1,S2,„,Sn),要求找到一个最 ...
- ubuntu adduser
ubuntu adduser 添加用户 hexan 到目录 /home/hexan 下.$ sudo adduser hexan -home /home/hexan 添加一个普通用户adduser [ ...
- Codeforces711
A ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on th ...
- nginx php fastcgi Connection reset by peer的原因及解决办法
Connection reset by peer 这个错误是在nginx的错误日志中发现的,为了更全面的掌握nginx运行的异常,强烈建议在nginx的全局配置中增加 error_log logs ...
- 【转载 save】vim键位图。
留图,备用,copy from 网络
- 「HTML5」url、href、src区别
一.URL的概念 统一资源定位符(或称统一资源定位器/定位地址.URL地址等,英语:Uniform Resource Locator,常缩写为URL),有时也被俗称为网页地址(网址).如同在网络上的门 ...
- C++字符串使用sizeof时注意
] = {"hello,你好"}; char tmp2[] = {"hello,你好"}; ]; sprintf(tmp3,"%s",&qu ...
- 还不会做! 树上的gcd 树分治 UOJ33
题目链接:http://uoj.ac/problem/33 题解链接:http://vfleaking.blog.uoj.ac/blog/38 现在感觉到了做OI的层层递进的思路的伟大之处,作为一个大 ...
- css纯数字或字母换行
#div { word-wrap:break-word; word-break:break-all; }