Could we add a lint warning for when the type parameter name overloads an existing type name?

Archie Cobbs archie.cobbs at gmail.com
Mon Apr 15 22:01:21 UTC 2024


On Mon, Apr 15, 2024 at 4:27 PM David Alayachew <davidalayachew at gmail.com>
wrote:

> > Java's decision to make the shadowing of normal variables illegal...
>
> I'm actually confused what you mean here.
>

Sorry, my fault for not being clear - Java only disallows "shadowing" for
variables declared in the same method, e.g., like this:

    public void foo(int x) {
        while (true) {
            float x = 1;     // error: variable x is already defined in
method foo(int)
            x += 7;
        }
    }

But it doesn't prevent variables from overshadowing fields as you point out.

-Archie

-- 
Archie L. Cobbs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20240415/06b46c69/attachment.htm>


More information about the amber-dev mailing list