I have a method which uses a String constant as shown below and the value is never used again.
@Service
public class Sample {
public void test(Greet greet) {
greet.setInitial("Hi");
}
}
The value for initial never changes and Sample class is a singleton bean.
My question is for the scenario should we declare a constant as shown below:
@Service
public class Sample {
private static final String INITIAL="Hi";
public void test(Greet greet) {
greet.setInitial(INITIAL)
}
}
And which approach is better from a performance perspective