Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMatthew Francis
6,967 Points"This" KeyWord
What is the difference between:
Toast.makeText(AClassIMade.this,name,"Message",.LENGTH_SHORT).show();
vs
Toast.makeText(this.AClassIMade,"Message",Toast.LENGTH_SHORT).show();
For some reason the second one does not work, any ideas why?
1 Answer
Gunjeet Hattar
14,483 PointsSimple answer Java syntax.
A more elaborated run down on this aspect-
ClassName.this this refers to the current object or instance of the class.
In Java dot operator denotes the hierarchy of things. So for example when we write System.out what is means is that there is a out method within the System class.
so if we write this.ClassName , Java interpreter will treat is as some classname method within the current instance of the class, which is not the case.
Hope that made sense. Happy to further explain if not clear.
Matthew Francis
6,967 PointsMatthew Francis
6,967 PointsThanks for the concise answer!