Consider the following code
public static void method(String[] srgs){
try{
}catch(){
System.out.println("Hello World" + "one");}
catch(..){
System.out.println("Hello World" + "two");}
catch(..){
System.out.println(getString());}
}
When are these lines created? I assume that Lines will be created when an Exception occurs at runtime. A string is created at runtime and displayed. My peer tells me that since they are constant Strings, they will be created as soon as the class loads. It is right?
When are Strings dumpsters collected? Do they collect garbage at all? Assuming the same method can be called many times during the life cycle of a program, does it make sense to just cache them?
source
share