Another, if the initialization is complicated and you have to do it at build time, provide a static method, returns the result, as in:
Code() { NEWLINE = newLineValue(); creation(); } Code(String name, int number) { NEWLINE = newLineValue(); creation(); name = new Something(name); number = new Magic(number); } private static String newLineValue() { return System.getProperty("line.separator"); }
In this case, newLineValue() trivial, so I would not use it here, but if there really was significant work, then it could be useful. You can also pass parameters from the constructor.
source share