Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3318962
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:46:06+00:00 2026-05-17T22:46:06+00:00

Is the following usage of this to refer to an instance variable in the

  • 0

Is the following usage of “this” to refer to an instance variable in the current class acceptable? In PHP this is how you would have to do it, but I noticed in Java you can just call the variable by name directly.

I personally find “this.variable” to be more understandable but I don’t want to develop bad coding habits if that isn’t normal.

Thanks!

public class MyClass {  

    /**
     * Private variable
     */
    private int myInt;

    /**
     * Setter method
     */
    public void setMyInt(int value) {
        this.myInt = value;
    }   
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T22:46:07+00:00Added an answer on May 17, 2026 at 10:46 pm

    Like people have been saying, its not required, but it is acceptable.

    That being said it is necessary if you’re doing something like this:

    private int value;
    
    public void setValue(int value) {
         this.value = value;
    }
    

    Which differentiates between the class variable and the parameter with the same name. I find myself using this pattern in almost every setter I make, and is about the only time I use the ‘this’ keyword.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've noticed the following pattern recently, but I don't entirely grasp the usage of
dose php5 forbid this usage, the following code doesn't work class Foo{ public static
I have been following the usage of JavaScript for the past few years, and
I have to maintain the following Perl script: #!/usr/bin/perl -w die Usage: $0 <file1>
How does the following example usage of extern specifer behave. We have a global
I'm hoping someone can explain the following usage of JavaScript. I have a page
I have the following string: nothing to match <- this rocks should match as
Given the following usage of auto : std::vector<int> v; for (auto i = 0;
Following on from a previous question relating to heap usage restrictions , I'm looking
Following code worked fine abstract class FunctionRunnable<V> implements Runnable { protected abstract V calculate();

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.