matches
Tells whether the actual type matches the expected.
Use Cases
Legend
Examples below refer to the types for simplicity; in fact, the respective TypeTokens for the types are passed into the method.
Rules
- The same types always match; e.g.
UserId.classalways matchesUserId.class. - Different types always don't match. e.g.
UserId.classalways does not matchNothing.class; - If
actualis a subtype ofexpected, they match. e.g.matches(EventMessage, Nothing)returnstrue. - The generic parameters are taken into account in a similar manner: same always match, a subtype matches a parent type, different types aren't matching; e.g. matches(Collection<EventMessage>, Set<ProjectEvent>) is
true; matches(Collection<EventMessage>, Set<CommandMessage>) isfalse. - If both
expectedandactualtypes define generic parameters, and the parameters containOptional<T>, the latter is "unpacked" for comparison. e.g. matches( Iterable<EventMessage>, Triplet<ProjectCreated, ProjectAssigned, Optional<ProjectStarted> ) istrue, matches(Optional<EventMessage>, Optional<AddTask>) isfalse. - Generic parameters with wildcard are not supported.