Is there a difference between intializing a variable with its declaration,
or in a static intialization?
The static intializer is called once by the classloader, which is exactly
what I want, but doing the initialization outside a static code block is
more readable (debatable). Is there a difference between the two?
private static final Map<MyEnum, Cheese> cheeseCache;
static {
parserCache = new EnumMap< MyEnum, String>(MyEnum.class){{
for(MyEnum myEnum: MyEnum.values()){
put(myEnum, new Cheese(myEnum)) ;
}
}};
}
or this :
private static final Map<Lab, LabResultParser> cheeseCache
= new EnumMap< MyEnum, String>(MyEnum.class){{
for(MyEnum myEnum: MyEnum.values()){
put(myEnum, new Cheese(myEnum)) ;
}
}};
No comments:
Post a Comment