🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #7943

Re: Language puzzle

#7943
From: John McGrath [TeamB]
Date: Thu, 03 May 2001 00:19
28 lines
2033 bytes
"Valentino Kyriakides" <vkyr@ision.net> wrote:

> No, because their inner used scoping for the "String s" is different. I
> think, thus the second ones String should been initialized first.

I think I understand what you are saying, in which case, it is pretty much
on target.  If 's' were initialized before the first 'if' statement, they
would be equivalent.

Java requires that all variables be "definitely assigned", which means that
the compiler must be able to verify, using relatively simple flow analysis,
that every variable will be assigned a value before it is used.

The first example passes that test.  The variable 's' is initialized on both
branches of the if-then-else, so it is definitely assigned.

The second example does not.  The compiler cannot examine the expressions
(b) and (!b) and determine that one of the two must be true, so 's' is not
definitely assigned.

So the most obvious difference between the two methods is that the first one
will compile, but the second will get a compiler error on the return
statement.

--
Regards,

John McGrath  [TeamB]
Technical Details
Message-ID: <3af0a403$1_2@dnews>
Path: arc1-ca.pugleaf.net!newsfeed.google.com!sn-xit-03!supernews.com!cyclone-sjo1.usenetserver.com!news-out-sjo.usenetserver.com!europa.netcrusader.net!128.230.129.106!news.maxwell.syr.edu!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!dnews
References: <3aef3645_1@dnews> <3af06553$1_1@dnews>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,b65cd5c59c7b0e70
X-Google-Attributes: gidf74b3,public
X-Google-ArrivalTime: 2001-05-02 17:28:03 PST
From: "John McGrath  [TeamB]" <ng-b@JPMcGrath.net>
Newsgroups: borland.public.jbuilder.java.language
References: <3aef3645_1@dnews> <3af06553$1_1@dnews>
Subject: Re: Language puzzle
Date: Wed, 2 May 2001 20:19:15 -0400
Lines: 31
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.00.2919.6600
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6600
NNTP-Posting-Host: 204.120.92.34
Message-ID: <3af0a403$1_2@dnews>
X-Trace: dnews 988849155 204.120.92.34 (2 May 2001 17:19:15 -0700)
Path: arc1-ca.pugleaf.net!newsfeed.google.com!sn-xit-03!supernews.com!cyclone-sjo1.usenetserver.com!news-out-sjo.usenetserver.com!europa.netcrusader.net!128.230.129.106!news.maxwell.syr.edu!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!dnews