I want to know if assign null to string literal, will it be eligible for garbage collection or not ?
String s = "abc";
s=null;
If not how can we achieve so ? Is there any way to clear literal pool ?
I want to know if assign null to string literal, will it be eligible for garbage collection or not ?
String s = "abc";
s=null;
If not how can we achieve so ? Is there any way to clear literal pool ?
I want to know if assign null to string literal
There is no way to assign null to a string literal. There is only a way to assign null to a reference, which is what your code below is doing.
will it be eligible for garbage collection or not?
No. It will remain in the constant pool until the class is unloaded.
String s = "abc";
s=null;
If not how can we achieve so?
You can't.
Is there any way to clear literal pool?
No.