I have written a base class for making request to repositories. It has a static field which is being used for some purpose in the application.
public abstract class RepositoryRequest {
private static String version;
{
version = 2.0; //Actual read is happening from some configuration file.
}
protected String getVersion() {
return version;
}
}
We have multiple request POJOs which extend this abstract class
public class ARepositoryRequest extends RepositoryRequest {
//Some properties here
@Override
public String toString() {
return "Some string generated by some logic" + getVersion();
}
}
Similarly other classes are also extending and overriding toString() method.
I have some doubts over garbage collection for these POJO objects:
1. Would this kind of usage of static variable will not let the POJO objects garbage collected?
2. Is there any issue with Objects/Classes in their garbage collection?