<div dir="ltr"><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Apr 27, 2020 at 5:38 AM Martin Kouba <<a href="mailto:mkouba@redhat.com">mkouba@redhat.com</a>> wrote:</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I think that you're right. Foo<E> is basically Foo<E extends Object> and <br>
according to the rules String is assignable to Object.</blockquote><div><br></div><div>Just to be clear, this test (that I added temporarily to <font face="monospace">CovariantTypesTest</font> and ran just to make sure) fails (as I'd expect):</div><div><font face="monospace"><br></font></div><div><font face="monospace">@Test<br>public <E> void testFooStringAssignableFromFooE() {<br> Type a = new TypeLiteral<Foo<String>>() {<br> }.getType();<br> Type b = new TypeLiteral<Foo<E>>() {<br> }.getType();</font></div><div><font face="monospace"> assertTrue(CovariantTypes.isAssignableFrom(a, b)); // kaboom<br>}</font><br></div><div><br></div><div>But this test (the one under discussion) in <font face="monospace">BeanTypeAssignabilityRules</font> succeeds (obviously or Weld's test suite would be broken):</div><div><br></div><div><font face="monospace">@Test<br>public <E> void testStringFooMatchesVariableFoo() throws Exception {<br> Type stringFooType = new TypeLiteral<Foo<String>>() {<br> }.getType();<br> Type variableFooType = new TypeLiteral<Foo<E>>() {<br> }.getType();<br> Assert.assertTrue("Foo<String> should match Foo<E>", getRules().matches(stringFooType, variableFooType));<br>}</font><br></div><div><br></div><div>So the rules CDI uses to do type matching (represented by <font face="monospace">BeanTypeAssignabilityRules</font>) are deliberately different from those used by JLS (represented by <font face="monospace">CovariantTypes</font>), right?</div><div><br></div><div>Best,</div><div>Laird</div></div></div>