Bug 21304 - Have option for compiler warning on redeclaration of instance/class variables as local variables
Summary: Have option for compiler warning on redeclaration of instance/class variables...
Status: RESOLVED DUPLICATE of bug 34173
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 3.0 M1   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-07-08 10:24 EDT by Jon Skeet CLA
Modified: 2003-06-12 06:41 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jon Skeet CLA 2002-07-08 10:24:11 EDT
One gotcha which people frequently run into is code such as:

public class Foo
{
    private String bar;

    public Foo(String value)
    {
        String bar=value;
    }

    [other code]
}

When bar is referred to in other code, it will be null rather than the value
passed to the constructor, as the assignment in the constructor is to a local
variable. Code with local variables with the same name as instance variables is
generally harder to read, with the possible exception of method parameters, eg:

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

is commonly idiomatic and should be okay.

One other compiler warning related to this, however, would be to flag the
assignment in:

public void setLongNamedParameter (String longNamesParameter)
{
    this.longNamedParameter = longNamedParameter;
}

as a no-op - note that the method parameter has a typo in it.

(This feature request is similar to 21109.)
Comment 1 Philipe Mulet CLA 2002-11-13 04:00:56 EST
The last item was resolved with fix for bug 25092.

The original issue remains, will defer post 2.1
Comment 2 Philipe Mulet CLA 2003-06-12 06:40:09 EDT
Diagnosis for variable hiding got addressed in 3.0 stream.
Comment 3 Philipe Mulet CLA 2003-06-12 06:41:13 EDT

*** This bug has been marked as a duplicate of 34173 ***