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


Groups > comp.lang.java.programmer > #33551 > unrolled thread

Re: Assignment or Initialization?

Started by4ndre4 <4ndre4@4ndre4.com.invalid>
First post2016-02-01 19:03 +0000
Last post2016-02-03 09:03 -0800
Articles 3 on this page of 23 — 10 participants

Back to article view | Back to comp.lang.java.programmer

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  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

Page 2 of 2 — ← Prev page 1 [2]


#33562

FromLew <lewbloch@gmail.com>
Date2016-02-02 10:32 -0800
Message-ID<5eea74f1-c7a6-4e75-a6e8-e3c028ad103b@googlegroups.com>
In reply to#33551
On Monday, February 1, 2016 at 11:04:09 AM UTC-8, 4ndre4 wrote:
> On 01/02/2016 12:23, Stefan Ram wrote:
> 
> [...]
> > final int i;
> > i = 3;
> 
> This is illegal.

Not a bit.

> 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.

Sure you can.

Look up "definitely assigned" and "definitely unassigned" and the rules for 'final' variables in the JLS.

-- 
Lew

[toc] | [prev] | [next] | [standalone]


#33563

From4ndre4 <4ndre4@4ndre4.com.invalid>
Date2016-02-02 19:22 +0000
Message-ID<n8qvgr$qv6$1@dont-email.me>
In reply to#33562
On 02/02/2016 18:32, Lew wrote:
[...]
> Sure you can.

You're right, you can. It means you can initialize a final variable, but 
not reassign a value to it.

-- 
4ndre4
"The use of COBOL cripples the mind; its teaching should, therefore, be 
regarded as a criminal offense." (E. Dijkstra)

[toc] | [prev] | [next] | [standalone]


#33575

FromDaniel Pitts <newsgroup.nospam@virtualinfinity.net>
Date2016-02-03 09:03 -0800
Message-ID<Zpqsy.229013$Gc6.58365@fx08.iad>
In reply to#33551
On 2/1/16 11:03 AM, 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.
>
You are confusing C++ with Java.

final int i;

if (something()) {
    i = 3;
} else {
    i = 5;
}

is perfectly valid.  As long as it is assigned "exactly once" before it 
is read, the compiler is happy.

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | comp.lang.java.programmer


csiph-web