Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

about "this "

 
lang lang
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm a Java beginer.Now I'm confused about "this ",would you please tell me
about "this "in different aspects? If you add some examples ,I will be greatful.
thanks a millon!
 
William Barnes
Ranch Hand
Posts: 986
Eclipse IDE Firefox Browser Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"this" is a referance to the current object.
 
Ransika deSilva
Ranch Hand
Posts: 524
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this might too explain what this means
Say if you have a class like this
public class Test {
int x = 0;
public Test(int x) {
x = x;

}
}
So how to deferenciate the two x's which one is global and one is local?
you can say
this.x = x;
now the 'this.x' is the global variable and x, which is assigned to it is the local variable.
Hope it is clear.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic