ECM
ECM
总版主
总版主
  • 社区居民
  • 忠实会员
  • 原创写手
阅读:2410亚博国际平台老虎机官网:0

“this” keyword in JAVA / Android programming?

楼主#
更多 发布于:2016-05-27 20:56
There is a block of code which is given below which i am trying to understand can anybody help me. public class MainActivity extends ActionBarActivity implements GestureDetector.OnGestureListener, GestureDetector.OnDoubleTapListener {
??protected void onCreate(){
?? ? ?private GestureDetectorCompat gestureDetector;
?? ? ?this.gestureDetector = new GestureDetectorCompat(this,this);
?? ? ?gestureDetector.setOnDoubleTapListener(this);

?? }
}
answer(解决方案):

The this keyword, which exists in many OOP languages, is a reference to the current instance of the object in which you are contained in memory.. Your example: this.gestureDetector = new GestureDetectorCompat(this,this);
?You are basically saying: This instance - access gestureDetector is equal to a new instance of GestureDetectorCompat that is constructed with 2 paramaters, in this case, both of them references to this instance of MainActivity. As people are saying, this is a fundamental principal and it may be more beneficial for you to start with building a strong foundation in Java before moving on to Android.

?

?

?

?

?

?

?

异常中心网是一家专门收集整理程序员编程过程中遇到的常见异常(exception)以及各种异常问答中心的网站。异常中心网旨在,减少程序员在编码遇到异常,处理各种异常时间和痛苦,让程序员能更愉快的、快速的定位异常并查找对应的异常解决方案。异常中心网诚心打造最完美的编程社区为程序员用户服务,努力成为最好的程序员乐园程序员社区程序异常中心程序bug中心异常问答中心

?

喜欢0 评分0
游客

返回顶部