I want to ask that if we should externalize string literals used in toString() implementations. Let me give an example :-
Suppose this is my toString() implementation :-
@Override
public String toString() {
return "First Name: " + firstName + "," + "Last Name: " + lastName;
}
Here, should we externalize “First Name: ” & “Last Name: ” or not?
Another scenario is with Validation Strings. If I am creating Name Object with first and last name with first name can not be null. Then I put the following check in my constructor :-
if(firstName == null) {
throw new NullPointerException("firstName is null");
}
Should we externalize “firstName is null” or not?
Thanks
You really only need to do that if you want to allow debugging messages to be internationalized since
toStringshouldn’t really be displayed to users