JavaHamcrest icon indicating copy to clipboard operation
JavaHamcrest copied to clipboard

Java 8 assertThat type safety lost

Open dmstocking opened this issue 9 years ago • 1 comments

Seems like Java 8 changes how generic arguments are resolved and now there is no type safety when using assertThat.

assertThat(1, is("abc"));

This now compiles and will fail at runtime. It would be nice if I knew immediately if my test were going to fail. If I were to guess I would think this is because the compiler just figures out that it can use Object for type T. Is there any way to fix this?

dmstocking avatar Oct 26 '16 21:10 dmstocking

Looks like you correct, Java 8 improves type inference: https://blog.jooq.org/2013/11/25/a-lesser-known-java-8-feature-generalized-target-type-inference/

arend-von-reinersdorff avatar Oct 27 '17 20:10 arend-von-reinersdorff