Hello, so we have the program below. The static block is last. Upon creation of the class, from my knowledge the first elements that will be created are static variables and static blocks of code.
My question is, considering that the static block of code will be created before the map element, how can we put elements in the map is this will be created later on?
It's like being in the present, going to the future to take some elements with you and coming back to the present to implement them even though they do not exist yet.
public class Solution {
public static Map<Double, String> labels = new HashMap<>();
public static void main(String[] args) {
System.out.println(labels);
}
static {
labels.put(2.33, "Caca");
labels.put(3.20, "Pipi");
labels.put(1.2, "dasa");
labels.put(4.44, "patru");
labels.put(5.778, "slas");
}
}