I have a class with as private List<String> children; which is currently initialized in the constructor but this is not always needed and I want to initialize it only when some other function need it.
The whole point is to rework current implementation without changing to much code.
I know how to do it in other languages, but Java knowledge is quite limited, so far.
To spell it out, this is one way of accomplishing it:
Also, remember to write eg.
addChild( String child )in terms of theget‘er rather than directly accessing the field. And if you’re really paranoid and/or in a threaded environment and the creation takes a long time, you might want to make the blocksynchronized.