Is synchronization needed in the case when I initialize a variable with a simple assignment and I don't care about the possibility of multiple initialization that could happen?
Like in this:
public class Something {
private static volatile Collection<String> data;
protected static Collection<String> data() {
if (data == null) {
final Set<String> dataToSet = new HashSet<String>();
dataToSet.add("value 1");
dataToSet.add("value 2");
data = dataToSet;
}
return data;
}
}