I was practicing the visitor pattern. And I found something interesting that the program created a new ArrayList inside the constructor, which confuses me.
For example:
class Computer implements ComputerPart
{
List<ComputerPart> parts;
public Computer(){
parts = new ArrayList<>(List.of(
new Mouse(),
new Keyboard(),
new Monitor()
));
}
Is that equals to:
class Computer implements ComputerPart
{
List<ComputerPart> parts = new ArrayList<>(List.of(
new Mouse(),
new Keyboard(),
new Monitor()
));
public Computer(){
}
Does that mean when creating the new Computer, then it will have a new ArrayList of the Keyboard, Mouse, and Monitor? Any help is highly appreciated.