This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug java/18147] New: Objects in instance initializer blocks are scoped too widely


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]