Open GoogleCodeExporter opened 9 years ago
After playing more with my code the following also compiles outside IDE
Assert.assertThat(4,Matchers<Integer>either(comparesEqualTo(4)).or(comparesEqual
To(3)));
Original comment by jmilkiew...@gmail.com
on 27 May 2009 at 5:54
Unfortunately, the design of Java generics seems to be flaky, so different
compilers sometimes interpret
differently. It also means that sometimes the compiler needs help with type
inference by locking down one of
the genericised arguments.
Have you tried this with equalTo(4), rather than going through a Comparable?
Rather than using intermediate objects, I sometimes use little helper methods
to construct a clause and force
the type. That also means I can give it a helpful name.
Original comment by smgfree...@gmail.com
on 28 May 2009 at 9:18
Hi
Thanks for an answer. Unfortunately this also does not compile:
Assert.assertThat(3, either(equalTo(4)).or(equalTo(3)));
It is a pity generics in Java works like that...
Original comment by jmilkiew...@gmail.com
on 28 May 2009 at 9:41
Btw the problems stands of course for arrays too, here's my simple workaround
assertThat(arrayOfTypeError, Matchers.<Error[]>
both(hasItemInArray(expectedError1)).and(hasItemInArray(expectedError2)));
instead of :
assertThat(arrayOfTypeError,
both(hasItemInArray(expectedError1)).and(hasItemInArray(expectedError2)));
This doesn't clutter the code too much, but for more complex matchers, I guess
using
a reference could be usefull.
Original comment by brice.du...@gmail.com
on 25 Sep 2009 at 12:19
Hi
A i stated in my second message i also try to help the compiler by specyfing
explicitly runtime parameter type for parametrized types.
Beside, IDE (eclipse) is not as restrictive as maven/ant compilation and some
of
these subtle generics bugs are only raised by my CI system.
Original comment by jmilkiew...@gmail.com
on 25 Sep 2009 at 2:31
tagging
Original comment by t.denley
on 12 May 2012 at 10:55
It is not just Eclipse VS JDK, the same issue can happen with different JDK
versions:
it compiled locally with maven using JDK 1.6.0u45, but not on CI with maven
using JDK 1.6.0u20.
Original comment by papp.robert.s
on 30 May 2014 at 4:46
Original issue reported on code.google.com by
jmilkiew...@gmail.com
on 27 May 2009 at 4:39