Skip to content

The copy constructor is showing inspection about suspicous copy or not all field copied if you try to do a deep copy. #7

@alain57

Description

@alain57

I implemented a copy constructor that needed to do a deep copy of on of acollection

neither of my classes are implementing the clonable interaface (don't need this ^^ )

Lets pretend I have follwing both classes

public class Bar {
	private int field1;
	private String field2;
	public Bar() {
	}
	
	public Bar(Bar other) {
		this.field1 = other.field1;
		this.field2 = other.field2;
	}
}
public class Foo {
	private List<Bar> bars;
	
	public Foo() {
	}
	
	public Foo(Foo other) {
		this.bars = other.bars
				.stream()
				.map(Bar::new)
				.collect(Collectors.toList());
	}
}

Basically the copy constructor of Foo is not doing any dark magic.
It makes a deep copy of the other object collection.

IMO the copy constructor of Foo class should not print any warning at all

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions