<p dir="ltr">Ty vm.</p>
<br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Tue, Jan 28, 2025, 11:58 AM Stephan Herrmann <<a href="mailto:stephan.herrmann@berlin.de">stephan.herrmann@berlin.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Am 28.01.25 um 17:40 schrieb David Alayachew:<br>
> Isn't null a value and not a type?<br>
<br>
null is a value, and null type is a type,<br>
see <a href="https://docs.oracle.com/javase/specs/jls/se23/html/jls-4.html#jls-4.1" rel="noreferrer noreferrer" target="_blank">https://docs.oracle.com/javase/specs/jls/se23/html/jls-4.html#jls-4.1</a><br>
<br>
> <br>
> On Tue, Jan 28, 2025, 9:25 AM Stephan Herrmann <<a href="mailto:stephan.herrmann@berlin.de" target="_blank" rel="noreferrer">stephan.herrmann@berlin.de</a> <br>
> <mailto:<a href="mailto:stephan.herrmann@berlin.de" target="_blank" rel="noreferrer">stephan.herrmann@berlin.de</a>>> wrote:<br>
> <br>
> Assume this (nonsense) program, which is accepted by javac and ecj:<br>
> <br>
> public class X {<br>
> public static void main(String[] args) {<br>
> switch (null) {<br>
> case null -> System.out.println("Null");<br>
> default-> System.out.println("Default");<br>
> }<br>
> }<br>
> }<br>
> <br>
> 14.1.1 Switch Blocks requires (T is the type of the selector expression):<br>
> * If a null literal is associated with the switch block, then T is a<br>
> reference type.<br>
> <br>
> In our case the selector expression has the null type, which can be assigned to<br>
> any reference type, but it doesn't seem to be a reference type itself.<br>
> <br>
> From this I would conclude that the program is illegal.<br>
> <br>
> <br>
> Next, lets remove the default case from the same program. Now compilers<br>
> complain, here's how javac puts it:<br>
> <br>
> X.java:3: error: the switch statement does not cover all possible input values<br>
> switch (null) {<br>
> ^<br>
> 1 error<br>
> <br>
> In previous discussions I learned that requiring a default label may be<br>
> justified by requirements of future changes, but here for this reasoning to<br>
> hold<br>
> the null type would need to acquire new values, which seems very unlikely :).<br>
> So, if the initial program would get the blessing from JLS, then also this case<br>
> (without default) deserves a second look.<br>
> <br>
> thanks,<br>
> Stephan<br>
> <br>
<br>
</blockquote></div>