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

David Alayachew davidalayachew at gmail.com
Mon Apr 15 23:10:47 UTC 2024


Thanks for clarifying. That makes sense.

In that respect, yes, I can't imagine a world where that would be legal.
Java absolutely made the right choice then.

But following your second example, I see what you mean. Still, I think
that, even then, a warning should have been made. Giving users a notice
that they are treading into dangerous waters is exactly the type of guard
rail that helps users make more confident decisions and increase adoption.

I say, rather late than never.

On Mon, Apr 15, 2024 at 6:01 PM Archie Cobbs <archie.cobbs at gmail.com> wrote:

> 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/3ee08d31/attachment.htm>


More information about the amber-dev mailing list