I've been following some tutorials to get used to libgdx while learning Java, and I found this piece of code in a class which intrigued me:
static Map<Keys, Boolean> keys = new HashMap<Keys, Boolean>();
static {
keys.put(Keys.LEFT, false);
keys.put(Keys.RIGHT, false);
keys.put(Keys.JUMP, false);
keys.put(Keys.FIRE, false);
};
You can mostly ignore the functionality of this. Keys is an enum and everything else should be self explanatory. The weird thing is that this piece of code is outside any method at all, and actually that static {} block is being declared as some kind of method.
So, what's this? What does it do? Does it execute that piece of code when the class is created? Or when the program first runs? (it's static after all). I'd just like to know what this kind of (let's call it) method is, if it's got a name, and what restrictions I've got using this. I'd also like to ask for some efficiency, or even good practise advice about wether to use this or avoid it.
Thank you very much.