title: Double {{ }} syntax question in java
body: <blockquote>
    <p><strong>Possible Duplicates:</strong><br>
    <a href="https://stackoverflow.com/questions/924285/efficiency-of-java-double-brace-initialization">Efficiency of Java &ldquo;Double Brace Initialization&rdquo;?</a><br>
    <a href="https://stackoverflow.com/questions/1372113/meaning-of-new-class-initialization-idiom">Meaning of new Class(&hellip;){{&hellip;}} initialization idiom</a>  </p>
  </blockquote>
  
  
  
  <p>Assume I  created a JMenu Bar the following way:</p>
  
  <pre>
  <code>
  JMenuItem saveMenuItem = new JMenuItem("Save")
      {{
         addActionListener(new ActionListener() {
  
                  public void actionPerformed(ActionEvent e)
                  {
                      String location = GUI.Custom.QuickDialogs.selectFile(false);
                      try
                      {
                          PrintWriter pw = new PrintWriter(new File(location));
                          String text = textArea.getText();
                          pw.println(text);
                          pw.flush();
                          pw.close();
                      }
                      catch(Exception ex)
                      {
                          textArea.append("Could not save this debug output");
                      }
                  }
              });
      }};
  
      JMenu optionsMenu = new JMenu("Options")
      {{
          add(saveMenuItem);
          setVisible(true);
      }};
  
      private JMenuBar menuBar = new JMenuBar()
      {{
         add(optionsMenu);
         setVisible(true);
      }};
  </code>
  </pre>
  
  <p>Is this a bad design pattern to create objects this way as opposed to just declaring the variable, and then creating in a constructor or something?</p>