Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

isA is not an equivalent to is(instanceOf()) #39

Closed
jonas-l opened this issue Aug 22, 2013 · 2 comments
Closed

isA is not an equivalent to is(instanceOf()) #39

jonas-l opened this issue Aug 22, 2013 · 2 comments

Comments

@jonas-l
Copy link

jonas-l commented Aug 22, 2013

isA() method currently accepts parameter of type Class<T> instead of Class<?>.

The following example fails to compile:

Object cheese = new Cheddar();
assertThat(cheese, isA(Cheddar.class));

while one with instanceOf() succeeds:

Object cheese = new Cheddar();
assertThat(cheese, is(instanceOf(Cheddar.class)));
@sf105
Copy link
Member

sf105 commented Aug 25, 2013

The isA method is intended to be used for plugging into type-checked expressions, such as jmock expectations, or where people want to use type checking as an early warning. instanceOf is where the constraint needs to be more forgiving. In a world with a better type system we probably wouldn't need both.

@sf105 sf105 closed this as completed Aug 25, 2013
@jonas-l
Copy link
Author

jonas-l commented Aug 25, 2013

It looks like this is actually a duplicate of #27 and is still valid. Furthermore, the isA comment states it's a shortcut for is(instanceOf()) but that's not true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants