Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #39959
| Path | csiph.com!news.mixmin.net!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Arne Vajhøj <arne@vajhoej.dk> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: switch is shared declaration |
| Date | Sun, 28 May 2023 13:42:22 -0400 |
| Organization | A noiseless patient Spider |
| Lines | 54 |
| Message-ID | <u503q0$va0v$1@dont-email.me> (permalink) |
| References | <af8aa265-141f-4887-8bae-83a9b2a0f9c1n@googlegroups.com> <u4ve27$3t8pn$1@gwaiyur.mb-net.net> <u4vhsg$sea0$1@dont-email.me> <u4vk7b$3t8pn$8@gwaiyur.mb-net.net> |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8; format=flowed |
| Content-Transfer-Encoding | 8bit |
| Injection-Date | Sun, 28 May 2023 17:42:24 -0000 (UTC) |
| Injection-Info | dont-email.me; posting-host="b44133095db4622383e5373aef64abf2"; logging-data="1026079"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19SXu25C11dMYBnneDlBaV2H8F0vbmfEw8=" |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.11.1 |
| Cancel-Lock | sha1:9Bo3ZjvHc0z0nV719zwkQp9rDLI= |
| In-Reply-To | <u4vk7b$3t8pn$8@gwaiyur.mb-net.net> |
| Content-Language | en-US |
| Xref | csiph.com comp.lang.java.programmer:39959 |
Show key headers only | View raw
On 5/28/2023 9:16 AM, Marcel Mueller wrote: > Am 28.05.23 um 14:36 schrieb Eric Sosman: >> On 5/28/2023 7:31 AM, Marcel Mueller wrote: >>> Shouldn't this be a problem too because the 2nd switch label bypasses >>> the initialization of s? >> >> The `case 1:' part *is* the initialization of `s'. There is a >> *declaration* of `s' in the `case -1:' part, but the declaration >> does nothing (here) to initialize the `s' reference. >> >> If we added another case to the switch, say >> >> default: >> System.out.println(s); >> break; >> >> ... the compiler would complain that `s' might be used without >> being initialized, true. But the code as shown does not try >> to retrieve any value from `s', so the compiler holds its peace. > > So ist is only valid because of the optimization? Not a traditional optimization. The check if things used are guaranteed to be initialized just do not apply. > String s; > is a default constructor call. No. s is just a reference not pointing to any object. > s = "1"; > is an assignment operator call. An assignment. > I expected the latter to be invalid without the first (unless String is > a trivial type). You can not assign to a variable not declared no matter whether it is simple or not. But I suspect that was not what you meant. String s; s = "1"; is sort of equivalent to C: char *s; s = "1"; Arne
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
switch is shared declaration "e.d.pro...@gmail.com" <e.d.programmer@gmail.com> - 2023-05-24 05:15 -0700
Re: switch is shared declaration Arne Vajhøj <arne@vajhoej.dk> - 2023-05-24 12:57 -0400
Re: switch is shared declaration Arne Vajhøj <arne@vajhoej.dk> - 2023-05-24 13:16 -0400
Re: switch is shared declaration "e.d.pro...@gmail.com" <e.d.programmer@gmail.com> - 2023-05-24 11:05 -0700
Re: switch is shared declaration Michael Jung <miju@golem.phantasia.org> - 2023-05-28 12:57 +0200
Re: switch is shared declaration Marcel Mueller <news.5.maazl@spamgourmet.org> - 2023-05-28 13:31 +0200
Re: switch is shared declaration Eric Sosman <esosman@comcast-dot-net.invalid> - 2023-05-28 08:36 -0400
Re: switch is shared declaration Marcel Mueller <news.5.maazl@spamgourmet.org> - 2023-05-28 15:16 +0200
Re: switch is shared declaration Arne Vajhøj <arne@vajhoej.dk> - 2023-05-28 13:42 -0400
Re: switch is shared declaration Arne Vajhøj <arne@vajhoej.dk> - 2023-05-28 13:43 -0400
csiph-web