For example, I have the following class that implements the Icon interface. In the constructor, it initializes the Color object by creating a deep copy of the Color object supplied in the parameter.
public class CircleIcon implements Icon { private Color iconColor; private int radius; public CircleIcon(Color iconColor, int radius) { this.iconColor = new Color(iconColor.getRGB()); this.radius = radius; } } My question is: Is this a proper way to initialize object of another class? I often see things like this in other people's code. In here, this.iconColor gets the reference of the Color object supplied in the parameter instead of its copy.
public CircleIcon(Color iconColor, int radius) { this.iconColor = iconColor; this.radius = radius; } I would like to know which way is preferred.