JavaHamcrest
JavaHamcrest copied to clipboard
Java 8 assertThat type safety lost
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?
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/