Skip to content

Incorrect variance in hasItem matcher #436

@CarstenLeue

Description

@CarstenLeue

The hasItem matcher has the signature

Matcher<Iterable<? super T>> hasItem(Matcher<? super T> itemMatcher)

but it should be

Matcher<Iterable<? extends T>> hasItem(Matcher<? super T> itemMatcher)

because the matcher needs to read items from the Iterable and it needs the contract that the sequence contains at least items of type T, so it should be covariant in T

The current implementation states the opposite, it would be applicable it the matcher wanted to write to the iterable, but that is (a) not possible, since there is no write operation on an iterable and (b) not its usecase.

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