[Logo]
Forums Register Login
What is 'this'?
I gone through some books and document but can't understood concept of 'this'. Can somebody elaborate the meaning and concept of 'this'. I got in mess with concept and use of 'this'. Please help me to understand following..

1) What is 'this'? Why it is used in language?
2) How much it is beneficial?
3) Where it is must?
4) Role of 'this' in threading?
5) A real life example to imagine the concept and importance of 'this'.

Thanks to all in advance.
If you do a search, you will find this comes up frequently. Several old threads: 1 2 3 and one example where I think "this" has been used inappropriately here.

Read those, and see whether they help; if not please ask again
1-3, 5 - Using the this Keyword
The "this" reference is a reference to the current object, if you use the "this" reference inside of a method or a constructor it will point to the actual object that was used to invoke this method.



It can be used to access member fields in case they are hidden/concealed (not sure what the actual English term for it is...) by local fields.
You can also use it to pass a reference to the current object to a method.

You could also have a look at the following url: http://java.sun.com/docs/books/tutorial/java/javaOO/thiskey.html

 

Dennis Korbar wrote:It can be used to access member fields in case they are hidden/concealed (not sure what the actual English term for it is...) by local fields.

I think (you can read it here in the Java Language Specification if you are feeling brave) the term is "shadowed."
Shadowed eh? There were quite a lot of translations for "verdeckt" on http://dict.leo.org but shadowed was not amongst them :-)
Thanks for the information!
You're welcome. I think shadowed is correct. Remember you are handicapped using dict.leo. It only translates into normal English :P
"this" refers to a current page you are working with. instead of you to call the file by name you simply refer to it by "this" helping to reduce tutology or errors by mispelling by mistake. this can also be used when you are writting threads.the role of "this" in threading is just that when you have many threads going on you can easily refer to the latest thread by referring to "this" instead of causing you confusion on the name of the particular thread you are working with
 

kelly devon wrote:"this" refers to a current page you are working with. instead of you to call the file by name you simply refer to it by "this" helping to reduce tutology or errors by mispelling by mistake. this can also be used when you are writting threads.the role of "this" in threading is just that when you have many threads going on you can easily refer to the latest thread by referring to "this" instead of causing you confusion on the name of the particular thread you are working with

Page? File? You mean an instance of a class, surely?

And what's tutology? How do you get a thread with the "this" keyword?
 

kelly devon wrote:"this" refers to a current page you are working with. instead of you to call the file by name you simply refer to it by "this" helping to reduce tutology or errors by mispelling by mistake. this can also be used when you are writting threads.the role of "this" in threading is just that when you have many threads going on you can easily refer to the latest thread by referring to "this" instead of causing you confusion on the name of the particular thread you are working with



Hogwash. There are no "pages" in Java, and the object to which "this" refers can't be referred to in any other way, so misspelling is not a danger. Furthermore, "this" has no special role with respect to threads in Java; as always, "this" refers to the object on which the method containing the executing code was invoked.
Wink, wink, nudge, nudge, say no more ... https://richsoil.com/cards


This thread has been viewed 1574 times.

All times above are in ranch (not your local) time.
The current ranch time is
Jan 17, 2018 19:19:46.