Have a look at this code:
private static Map< String, Method > supplierFunctionMap = new HashMap< String, Method >();
static
{
try {
//ARP
supplierFunctionMap.put( "206175-200", SupplierConfiguration.class.getDeclaredMethod("asd", String.class));
supplierFunctionMap.put( "206175-210", SupplierConfiguration.class.getDeclaredMethod("asd", String.class));
supplierFunctionMap.put( "206175-998", SupplierConfiguration.class.getDeclaredMethod("asd", String.class));
//ADD new suppliers below
} catch (NoSuchMethodException e) {
System.out.println("Error in Key / Value of Hashmap. Maybe Key or Value not existing or something else is wrong.");
e.printStackTrace();
}
}
The code under static{
is somehow connected with the hashmap
.
Because If I call this:
supplierFunctionMap.get("206175-200").invoke(null, supplierNumberAndAdmnr);
Then the getDeclared
method is called.
Can somebody explain why static{
like this can be declared and how it gets connected with the hashmap
?