public inbox for java-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug java/18147] New: Objects in instance initializer blocks are scoped too widely
@ 2004-10-25 18:46 csm at gnu dot org
  2004-10-25 18:49 ` [Bug java/18147] " pinskia at gcc dot gnu dot org
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: csm at gnu dot org @ 2004-10-25 18:46 UTC (permalink / raw)
  To: java-prs

If you declare an object within an instance initializer, you cannot declare
another object of the same name in a different instance initializer.

This description seems pretty opaque, so an example of correct code that GCJ
rejects is probably better:

-- init.java --
import java.util.HashMap;
class init
{
  private final HashMap _map1 = new HashMap();
  {
    Object foo = new Object();
    _map1.put ("foo!", foo);
  }

  private final HashMap _map2 = new HashMap();
  {
    Object foo = new Object();
    _map2.put ("bar!", foo);
  }
}
-- init.java --

GCJ exits with this error:

init.java:13: error: Variable `foo' is already defined in this method and was
declared `Object foo' at line 7.
       Object foo = new Object();
              ^
1 error

-- 
           Summary: Objects in instance initializer blocks are scoped too
                    widely
           Product: gcc
           Version: 3.4.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: java
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: csm at gnu dot org
                CC: gcc-bugs at gcc dot gnu dot org,java-prs at gcc dot gnu
                    dot org
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18147


^ permalink raw reply	[flat|nested] 5+ messages in thread
[parent not found: <bug-18147-9192@http.gcc.gnu.org/bugzilla/>]

end of thread, other threads:[~2007-01-09 20:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-25 18:46 [Bug java/18147] New: Objects in instance initializer blocks are scoped too widely csm at gnu dot org
2004-10-25 18:49 ` [Bug java/18147] " pinskia at gcc dot gnu dot org
2004-10-25 18:55 ` tromey at gcc dot gnu dot org
2005-01-24  0:57 ` pinskia at gcc dot gnu dot org
     [not found] <bug-18147-9192@http.gcc.gnu.org/bugzilla/>
2007-01-09 20:49 ` tromey at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).