<div dir="ltr"><div style="font-family:monospace" class="gmail_default"><br>Hello Archie,<br><br>Thank you for your response!<br><br>> I agree this seems like it would be an improvement. A<br>> slight variant of the problem that I've witnessed cause<br>> confusion multiple times is this (boiled down):<br>> <br>> public class MyClass<T> {<br>>     public <T> void foo() {<br>>         // easy to confuse what "T" means here<br>>     }<br>> }<br><br>Yeah, I have been bitten by this one too. I would very much like it if this also got bundled into the warning concept that I proposed.<br><br>Shadowing is useful since it facilitates migration, but it has the sharp edge of making future updates a little more error-prone. Leaving it as is might make sense, but those who want it would likely appreciate a guard rail in the form of a warning.<br><br>> Java's decision to make the shadowing of normal variables illegal...<br><br>I'm actually confused what you mean here. When you say shadowing of normal variables, I am interpreting something like the following example.<br><br>public class tuv<br>{<br><br>    int x = 0;<br><br>    public void someMethod()<br>    {<br>    <br>        int x = 2;<br>        <br>        System.out.println(x); //prints 2<br>    <br>    }<br>    <br>    public void anotherMethod()<br>    {<br>    <br>        System.out.println(x); //prints 0<br>    <br>    }<br><br>}<br><br>But the above example is legal Java. Could you clarify?<br><br>Since the rest of your email builds on that point, I'm not able to follow along.<br><br>Thank you for your help!<br>David Alayachew<br></div><div class="gmail_default" style="font-family:monospace"><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Apr 15, 2024 at 12:19 PM Archie Cobbs <<a href="mailto:archie.cobbs@gmail.com">archie.cobbs@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div>Replying only to amber-dev for now...</div><div><br></div><div>I agree this seems like it would be an improvement. A slight variant of the problem that I've witnessed cause confusion multiple times is this (boiled down):<br></div><div><br></div><div style="margin-left:40px"><span style="font-family:monospace">public class MyClass<T> {<br>    public <T> void foo() {</span></div><div style="margin-left:40px"><span style="font-family:monospace">        // easy to confuse what "T" means here<br></span></div><div style="margin-left:40px"><span style="font-family:monospace">    }<br>}</span></div><div><br></div><div>Java's decision to make the shadowing of normal variables illegal was a nice "advance" at the time, and I've always wondered why it shouldn't carry over to generic type variables as well. It seems like the same basic principle would apply.</div><div><br></div><div>Or maybe not?</div><div><br></div><div>Generic type variables are a kind of combination of "type name" and "variable". While Java doesn't allow shadowing for variables, it does for type names - for example:</div><div><br></div><div style="margin-left:40px"><span style="font-family:monospace">public class MyClass<T> {<br>    public class String {   // no error here<br>    }<br>    public class T {        // no error here<br>    }<br>}</span><br></div><div><br></div><div>So maybe Java was just making the conservative choice at the time.<br></div><div><br></div><div>-Archie<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Apr 14, 2024 at 10:33 PM David Alayachew <<a href="mailto:davidalayachew@gmail.com" target="_blank">davidalayachew@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">In the vein of smoothing the on-ramp for beginners, one of the biggest pain points I have found when tutoring beginners is when they start to learn generics, and then do something like this.</div>
</blockquote></div><br clear="all"><br><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature">Archie L. Cobbs<br></div></div>
</blockquote></div>