What is Double Brace initialization in Java?

前端 未结 13 2285
旧时难觅i
旧时难觅i 2020-11-21 07:22

What is Double Brace initialization syntax ({{ ... }}) in Java?

13条回答
  •  不思量自难忘°
    2020-11-21 07:51

    For a fun application of double brace initialization, see here Dwemthy’s Array in Java.

    An excerpt

    private static class IndustrialRaverMonkey
      extends Creature.Base {{
        life = 46;
        strength = 35;
        charisma = 91;
        weapon = 2;
      }}
    
    private static class DwarvenAngel
      extends Creature.Base {{
        life = 540;
        strength = 6;
        charisma = 144;
        weapon = 50;
      }}
    

    And now, be prepared for the BattleOfGrottoOfSausageSmells and … chunky bacon!

提交回复
热议问题