I have immutable class and want add new constructor without duplicating code in both constructors.
I have class:
public class Test { private final String stringParameter; public Test() { stringParameter = "firstReallyLongDefaultString"; } public Test(String s) { stringParameter = s; } } And I want to add the new constructor with "char" parameter, something like this:
public Test(char s) { if(Character.isLetter(s)) { stringParameter = "firstReallyLong" + s + "DefaultString"; } else { stringParameter = "firstReallyLongDefaultString"; } } How can I do it without the code repetition of the long string? I would like to call "this()" constructor in else branch but it's not possible.