Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: keyword "this"

  1. #1
    New Coder
    Join Date
    Feb 2013
    Posts
    45
    Thanks
    8
    Thanked 0 Times in 0 Posts

    keyword "this"

    Just a quick question.

    Should we get used to using "this.variableName" or just use a different name?

    What would programmers with lots of experience commonly use?

    Thanks

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Java uses variable masking for its member properties, so this. is not required unless you are naming properties the same as local variables or arguments (which I often do).
    I always use this. though, its a habit since I do so much PHP programming which does not have scope masking for its variables or methods.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    New to the CF scene
    Join Date
    Mar 2013
    Location
    Bangladesh
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Friend can you tell me? is it only for java?

  • #4
    New to the CF scene
    Join Date
    Mar 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Java defines the this keyword. this can be used inside any method to refer to the current object. That is, this is always a reference to the object on which the method was invoked. You can use this anywhere a reference to an object of the current class' type is permitted.

    Example:

    public class Class2{

    int number;
    public Class2(int number){
    this.number = number;
    }
    }


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •