I have some knowledge about string pool in Java. All examples in the network conected with creating variables explicitly. But what will happen if I return hardcoded string from method. Is it use string pool or string will be created again and again for each method call. I can't find any information about this case.
I have such example:
public class TestService {
@Override
protected Optional<String> getPayTypeCode() {
return Optional.of("LDV");
}
//...
}
Example with constant:
public class TestService {
private static final String PAY_CODE = "LDV";
@Override
protected Optional<String> getPayTypeCode() {
return Optional.of(PAY_CODE);
}
//...
}
And I am wondering, is my first case use string pool? And which case will work faster?