2

For Instance case:1) Using inner-loop static block and assigning values, as below:

public class MyClass
{
public static final Map<String, String> CARD_TYPES;

static
    {
        CARD_TYPES = new HashMap<String, String>()
        {
            {  
                put("visa", "001");
                put("diner", "002");
            }
        };
    }
//..code goes here
}

case:2) Directly Assigning using in Static block, as below:

public class MyClass
    {
    public static final Map<String, String> CARD_TYPES = new HashMap<String, String>();
    
    static
        {         
                CARD_TYPES.put("visa", "001");
                CARD_TYPES.put("diner", "002");
        }
    //..code goes here
    }
Sunil
  • 71
  • 1
  • 11
  • Is the first example exactly the one you mean? That's not an "inner loop static block," but a use of the double-brace initialization pattern as you wrote it, which is [notably inefficient](https://stackoverflow.com/q/924285/869736). – Louis Wasserman Nov 01 '20 at 17:13

0 Answers0