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 9154167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:23:13+00:00 2026-06-17T12:23:13+00:00

I have an IDE which I can use to automatically create constructors and setters

  • 0

I have an IDE which I can use to automatically create constructors and setters for instance variables, but I was wondering if the way that it creates them is possibly not best practice. Here is what it does:

private String partNum;
private String partDesc;
private int quant;
private double price;

public Invoice( String partNum, String partDesc, int quant, double price )
{
    this.partNum = partNum;
    this.partDesc = partDesc;
    this.quant = quant;
    this.price = price;
}

It’s the ‘this.name’ thing that I’m worried about, as well as the constructor labeling the parameters the same names as the variables it’s constructing. The setter also does the same thing — uses a parameter name that’s the same as the name of the variable it’s setting, and uses this.name.

So, is there anything wrong with this?

  • 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-06-17T12:23:14+00:00Added an answer on June 17, 2026 at 12:23 pm

    What you are witnessing is pretty standard Java practice, and is even mentioned in the Java Language Specification:

    If a name declared as a local variable is already declared as a field
    name, then that outer declaration is shadowed (§6.3.1) throughout the
    scope of the local variable. Similarly, if a name is already declared
    as a variable or parameter name, then that outer declaration is
    shadowed throughout the scope of the local variable (provided that the
    shadowing does not cause a compile-time error under the rules of
    §14.4.2). The shadowed name can sometimes be accessed using an
    appropriately qualified name.

    For example, the keyword this can be used to access a shadowed field
    x, using the form this.x. Indeed, this idiom typically appears in
    constructors (§8.8):

    class Pair {
            Object first, second;
            public Pair(Object first, Object second) {
                    this.first = first;
                    this.second = second;
            }
    }
    

    In this example, the constructor takes parameters having the same
    names as the fields to be initialized. This is simpler than having to
    invent different names for the parameters and is not too confusing in
    this stylized context. In general, however, it is considered poor
    style to have local variables with the same names as fields.

    When local variables to a method have the same name as class variables, they effectively ‘shadow’ or hide those variables. But you can still access the class variables by referring to them via the this context scope.

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

Sidebar

Related Questions

I have a Selenium IDE (version 1.7.2) test that I use to test the
I must have a IDE for VB6. I can't use DotNet, because I cannot
I have tried to use the NodeJS plugin in IntelliJ IDEA CE but can't
I have a selenium script that I created with Selenium IDE. I was wondering
We have several projects that use p4.net , a managed DLL, which in turn
I have an Android project in eclipse IDE which was working. After some imports
I have a c# code.(which is exported from selenium IDE) using System; using System.Text;
Using JDeveloper as my IDE, I have a web application which calls services provided
I still have to use the VB6 IDE. Unfortunately every time I start the
We use Selenium IDE to record the test. In the recorder we can change

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.