What is the difference (memory-wise) between
private static final String FAILURE_MESSAGE= "...";
protected String getFailedMsg() {
return FAILURE_MESSAGE;
}
And
protected String getFailedMsg() {
return "...";
}
Assuming that the FAILURE_MESSAGE is only referenced from the above function.
I mean where and how are the above objects/strings being held in memory in the above cases? Is it JVM specific?
Edit: I know that the string is interned in the first approach, but where is it value being stored/held/(interned?) in the second approach before the function is called?
Second edit as an afterthought - what if the strings are replaced with ints or some other class that is not a string?
"..."will reference the same instance in memory.