Skip to content

Array is mutable #37

@pluresideas

Description

@pluresideas

Array consisting of mutable objects is mutable which contradicts the project's documentation.

The following tests fails:

    /**
     * Array must be immutable
     */
    @Test
    public void isImmutable() {
        final Mutable[] ints = new Mutable[]{new Mutable(1), new Mutable(2), new Mutable(3)};
        final Array<Mutable> array = new Array<Mutable>(ints);
        ints[1].setState(200);
        Assert.assertTrue(
                Arrays.equals(array.toArray(), new Mutable[]{new Mutable(1), new Mutable(2), new Mutable(3)})
        );
    }

public class Mutable {

    Integer state;

    public Mutable(Integer state) {
        this.state = state;
    }

    public Integer getState() {
        return state;
    }

    public void setState(Integer state) {
        this.state = state;
    }

    @Override
    public int hashCode() {
        return state;
    }

    @Override
    public boolean equals(Object obj) {
        return state.equals(((Mutable)obj).getState());
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions