Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #33552

Re: Assignment or Initialization?

Path csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail
From Eric Sosman <esosman@comcast-dot-net.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: Assignment or Initialization?
Date Mon, 1 Feb 2016 14:47:58 -0500
Organization A noiseless patient Spider
Lines 41
Message-ID <n8ockg$b4a$1@dont-email.me> (permalink)
References <assignment-20160201130855@ram.dialup.fu-berlin.de> <n8oa1b$tq9$2@dont-email.me>
Mime-Version 1.0
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 7bit
Injection-Date Mon, 1 Feb 2016 19:45:20 -0000 (UTC)
Injection-Info mx02.eternal-september.org; posting-host="2d081e2f7155c28005d4472f67c2f43d"; logging-data="11402"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/R2V8HOXbNM1DWnF05Eign"
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1
In-Reply-To <n8oa1b$tq9$2@dont-email.me>
Cancel-Lock sha1:PSX0a6JVXEAskSs2hx5j/+dj8sw=
Xref csiph.com comp.lang.java.programmer:33552

Show key headers only | View raw


On 2/1/2016 2:03 PM, 4ndre4 wrote:
> On 01/02/2016 12:23, Stefan Ram wrote:
>
> [...]
>> final int i;
>> i = 3;
>
> This is illegal.
>
> final int i = 3;
>
> is the correct form: initialization. You can't declare a final variable
> and THEN assign a value to it, unless you are in a constructor, in which
> case it's still an initialization.

     What you say is true (I think) if `i' is a class member.
But it's untrue for local variables, where constructs like

             final boolean leftClick;
             switch (mouseEvent.getButton()) {
                case MouseEvent.BUTTON1:
                   leftClick = true;
                   break;
                case MouseEvent.BUTTON3:
                   leftClick = false;
                   break;
                default:
                   // Unidentifiable mouse button: Ignore.
                   return;
             }

... work exactly as one would expect: `leftClick' is given only
one value and is thereafter immutable, but the value comes from one
of two (in this case) assignment statements.

     Whether this is counts as an "assignment" or as an "initialization"
is not something I lose sleep over.

-- 
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Re: Assignment or Initialization? 4ndre4 <4ndre4@4ndre4.com.invalid> - 2016-02-01 19:03 +0000
  Re: Assignment or Initialization? Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-02-01 14:47 -0500
    Re: Assignment or Initialization? Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2016-02-01 12:31 -0800
      Re: Assignment or Initialization? Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-02-01 16:03 -0500
        Re: Assignment or Initialization? Jerry Stuckle <jstucklex@attglobal.net> - 2016-02-01 19:52 -0500
          Re: Assignment or Initialization? Arne Vajhøj <arne@vajhoej.dk> - 2016-02-01 20:46 -0500
          Re: Assignment or Initialization? Wayne <nospam@all.invalid> - 2016-02-01 23:39 -0500
            Re: Assignment or Initialization? Jerry Stuckle <jstucklex@attglobal.net> - 2016-02-02 09:14 -0500
      Re: Assignment or Initialization? 4ndre4 <4ndre4@4ndre4.com.invalid> - 2016-02-02 19:25 +0000
  Re: Assignment or Initialization? Eric Douglas <e.d.programmer@gmail.com> - 2016-02-01 13:13 -0800
    Re: Assignment or Initialization? 4ndre4 <4ndre4@4ndre4.com.invalid> - 2016-02-02 19:26 +0000
  Re: Assignment or Initialization? Arne Vajhøj <arne@vajhoej.dk> - 2016-02-01 20:55 -0500
    Re: Assignment or Initialization? 4ndre4 <4ndre4@4ndre4.com.invalid> - 2016-02-02 19:29 +0000
      Re: Assignment or Initialization? Eric Douglas <e.d.programmer@gmail.com> - 2016-02-02 11:44 -0800
        Re: Assignment or Initialization? Lew <lewbloch@gmail.com> - 2016-02-02 13:16 -0800
      Re: Assignment or Initialization? Lew <lewbloch@gmail.com> - 2016-02-02 13:15 -0800
      Re: Assignment or Initialization? Arne Vajhøj <arne@vajhoej.dk> - 2016-02-02 18:13 -0500
      Re: Assignment or Initialization? Silvio <silvio@internet.com> - 2016-02-03 12:10 +0100
        Re: Assignment or Initialization? Eric Douglas <e.d.programmer@gmail.com> - 2016-02-03 05:14 -0800
          Re: Assignment or Initialization? Lew <lewbloch@gmail.com> - 2016-02-03 13:39 -0800
  Re: Assignment or Initialization? Lew <lewbloch@gmail.com> - 2016-02-02 10:32 -0800
    Re: Assignment or Initialization? 4ndre4 <4ndre4@4ndre4.com.invalid> - 2016-02-02 19:22 +0000
  Re: Assignment or Initialization? Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2016-02-03 09:03 -0800

csiph-web